MCPcopy Create free account
hub / github.com/WebMCP-org/chrome-devtools-quickstart / aggregateBenchmarkResults

Function aggregateBenchmarkResults

benchmark/helpers.ts:785–829  ·  view source on GitHub ↗
(
  approach: string,
  results: AgentBenchmarkResult[]
)

Source from the content-addressed store, hash-verified

783}
784
785export function aggregateBenchmarkResults(
786 approach: string,
787 results: AgentBenchmarkResult[]
788): AggregatedBenchmarkResults {
789 const n = results.length;
790 if (n === 0) {
791 return {
792 approach,
793 runs: [],
794 avgInputTokens: 0,
795 avgOutputTokens: 0,
796 avgImageTokens: 0,
797 avgTotalCostUsd: 0,
798 avgDurationMs: 0,
799 avgNumTurns: 0,
800 successRate: 0,
801 };
802 }
803
804 const sum = (key: keyof AgentBenchmarkResult) =>
805 results.reduce((acc, r) => acc + (r[key] as number), 0);
806
807 const totalToolUsage: Record<string, number> = {};
808 for (const result of results) {
809 if (result.toolUsage) {
810 for (const [tool, count] of Object.entries(result.toolUsage)) {
811 totalToolUsage[tool] = (totalToolUsage[tool] || 0) + count;
812 }
813 }
814 }
815
816 return {
817 approach,
818 runs: results,
819 avgInputTokens: sum("inputTokens") / n,
820 avgOutputTokens: sum("outputTokens") / n,
821 avgImageTokens: sum("imageTokens") / n,
822 avgTotalCostUsd: sum("totalCostUsd") / n,
823 avgDurationMs: sum("durationMs") / n,
824 avgNumTurns: sum("numTurns") / n,
825 successRate: results.filter((r) => r.success).length / n,
826 totalToolUsage:
827 Object.keys(totalToolUsage).length > 0 ? totalToolUsage : undefined,
828 };
829}
830
831/**
832 * Prints formatted results for a single approach (Agent SDK version).

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 1

sumFunction · 0.85

Tested by

no test coverage detected