Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore(bench): add report and format modules for benchmark harness

Steven Enamakel47c6e5ab336c
diff --git a/bench/harnesses/format.mjs b/bench/harnesses/format.mjs
new file mode 100644
index 0000000000..5dff424ff7
--- /dev/null
+++ b/bench/harnesses/format.mjs
@@ -0,0 +1,53 @@
+// format.mjs — one place for how benchmark numbers are shown, used by the Markdown
+// report and the web viewer (served to the browser as /format.mjs). Raw numbers stay
+// raw in summary.json; this is display only.
+//
+// count(248845) -> "248.8k" count(9876) -> "9,876" count(2_400_000) -> "2.40M"
+// mem(351) -> "351 MB" mem(1536) -> "1.50 GB" mem(0.4) -> "410 KB" (input in MB)
+// ms(696) -> "696 ms" ms(1240) -> "1.24 s" ms(95000) -> "1m 35s"
+// secs(4.7) -> "4.7 s" usd(0.00184) -> "$0.0018" pct(97.31) -> "97.3%"
+
+const NONE = "–";
+const has = (v) => v !== null && v !== undefined && Number.isFinite(Number(v));
+const grouped = (n, d = 0) => n.toLocaleString("en-US", { minimumFractionDigits: d, maximumFractionDigits: d });
+
+/** Token / call / item counts: commas below 10,000, then k, M, B with 3 significant digits. */
+export function count(v) {
+ if (!has(v)) return NONE;
+ const n = Number(v);
+ const a = Math.abs(n);
+ if (a < 10_000) return grouped(Math.round(n));
+ if (a < 1_000_000) return `${grouped(n / 1e3, 1)}k`;
+ if (a < 1e9) return `${grouped(n / 1e6, 2)}M`;
+ return `${grouped(n / 1e9, 2)}B`;
+}
+
+/** Memory, given in MB (binary: 1 GB = 1024 MB). */
+export function mem(mb) {
+ if (!has(mb)) return NONE;
+ const n = Number(mb);
+ if (n >= 1024) return `${grouped(n / 1024, 2)} GB`;
+ if (n >= 1) return `${grouped(n, n < 10 ? 1 : 0)} MB`;
+ return `${grouped(n * 1024, 0)} KB`;
+}
+
+/** Durations given in milliseconds. */
+export function ms(v) {
+ if (!has(v)) return NONE;
+ const n = Number(v);
+ if (n < 1000) return `${grouped(Math.round(n))} ms`;
+ if (n < 60_000) return `${grouped(n / 1000, n < 10_000 ? 2 : 1)} s`;
+ const s = Math.round(n / 1000);
+ return `${Math.floor(s / 60)}m ${String(s % 60).padStart(2, "0")}s`;
+}
+
+/** Durations given in seconds. */
+export const secs = (v) => (has(v) ? ms(Number(v) * 1000) : NONE);
+
+export function usd(v) {
+ if (!has(v)) return NONE;
+ const n = Number(v);
+ return `$${n < 0.01 ? n.toFixed(4) : n < 100 ? n.toFixed(2) : grouped(n, 0)}`;
+}
+
+export const pct = (v, d = 1) => (has(v) ? `${grouped(Number(v), d)}%` : NONE);
diff --git a/bench/harnesses/format.test.mjs b/bench/harnesses/format.test.mjs
new file mode 100644
index 0000000000..9988ce12c1
--- /dev/null
+++ b/bench/harnesses/format.test.mjs
@@ -0,0 +1,35 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { count, mem, ms, pct, secs, usd } from "./format.mjs";
+
+test("count: commas under 10k, then k / M / B", () => {
+ assert.equal(count(0), "0");
+ assert.equal(count(9876), "9,876");
+ assert.equal(count(10_000), "10.0k");
+ assert.equal(count(248_845), "248.8k");
+ assert.equal(count(2_400_000), "2.40M");
+ assert.equal(count(3_100_000_000), "3.10B");
+ assert.equal(count(null), "–");
+});
+
+test("mem: MB input to KB / MB / GB", () => {
+ assert.equal(mem(0.4), "410 KB");
+ assert.equal(mem(5.25), "5.3 MB");
+ assert.equal(mem(351), "351 MB");
+ assert.equal(mem(1536), "1.50 GB");
+ assert.equal(mem(undefined), "–");
+});
+
+test("ms / secs: ms, s, then minutes", () => {
+ assert.equal(ms(696), "696 ms");
+ assert.equal(ms(1240), "1.24 s");
+ assert.equal(ms(12_400), "12.4 s");
+ assert.equal(ms(95_000), "1m 35s");
+ assert.equal(secs(4.7), "4.70 s");
+});
+
+test("usd and pct", () => {
+ assert.equal(usd(0.00184), "$0.0018");
+ assert.equal(usd(1.5), "$1.50");
+ assert.equal(pct(97.31), "97.3%");
+});
diff --git a/bench/harnesses/report.mjs b/bench/harnesses/report.mjs
index 237bcd6fcb..ced1995555 100644
--- a/bench/harnesses/report.mjs
+++ b/bench/harnesses/report.mjs
@@ -140,8 +140,10 @@ export function aggregate(meter, tasks) {
return out;
}
+import { count, mem, ms, pct, secs, usd } from "./format.mjs";
+
const f = (v, d = 0) => (v === null || v === undefined ? "-" : Number(v).toFixed(d));
-const money = (v) => (v === null || v === undefined ? "-" : `$${Number(v).toFixed(4)}`);
+const money = (v) => (v === null || v === undefined ? "-" : usd(v));
export function toMarkdown(meta, summary) {
const names = Object.keys(summary);
@@ -149,23 +151,23 @@ export function toMarkdown(meta, summary) {
["resolved (SWE) / checks passed", (s) => (s.swe_resolved === null ? `${s.check_passed}/${s.tasks} checks` : `${s.swe_resolved}/${s.swe_graded} resolved`)],
["patch produced", (s) => `${s.patch_produced}/${s.tasks}`],
["harness errors / timeouts (all tasks)", (s) => `${s.harness_errors} / ${s.timeouts}`],
- ["system prompt tokens", (s) => f(s.system_prompt_tokens)],
- ["tool schema tokens (count)", (s) => `${f(s.tool_schema_tokens)} (${f(s.tool_count)})`],
- ["static prompt total (system + tools)", (s) => f(s.solved_static_prompt_tokens ?? s.static_prompt_tokens)],
+ ["system prompt tokens", (s) => count(s.system_prompt_tokens)],
+ ["tool schema tokens (count)", (s) => `${count(s.tool_schema_tokens)} (${count(s.tool_count)})`],
+ ["static prompt total (system + tools)", (s) => count(s.solved_static_prompt_tokens ?? s.static_prompt_tokens)],
["cost / solved task", (s) => money(s.cost_per_solved_usd)],
- ["tokens / solved task", (s) => f(s.tokens_per_solved)],
+ ["tokens / solved task", (s) => count(s.tokens_per_solved)],
["total cost (all tasks)", (s) => `${money(s.cost_usd)}${s.cost_unpriced_calls ? ` (+${s.cost_unpriced_calls} unpriced)` : ""}`],
- ["cache hit % (solved tasks)", (s) => f(s.solved_cache_pct, 1)],
- ["TTFT p50 (ms, solved tasks)", (s) => f(s.solved_ttft_ms_p50)],
- ["LLM call latency p50 (ms, solved tasks)", (s) => f(s.solved_call_latency_ms_p50)],
- ["task wall p50 (s, solved tasks)", (s) => f(s.solved_task_wall_s_p50, 1)],
- ["cold start to first call p50 (ms, solved tasks)", (s) => f(s.solved_cold_start_ms_p50)],
- ["CPU-seconds / solved task", (s) => f(s.solved_cpu_seconds_mean, 1)],
- ["peak RAM, process memory (MB, solved tasks)", (s) => f(s.solved_peak_anon_mb_max)],
- ["peak RAM incl. page cache (MB, all tasks)", (s) => f(s.peak_mem_mb_max)],
- ["avg RAM (MB, all tasks)", (s) => f(s.avg_mem_mb_mean)],
- ["LLM calls (errors)", (s) => `${s.llm_calls} (${s.llm_call_errors})`],
- ["prompt / completion tokens", (s) => `${s.prompt_tokens} / ${s.completion_tokens}`],
+ ["cache hit % (solved tasks)", (s) => pct(s.solved_cache_pct)],
+ ["TTFT p50 (solved tasks)", (s) => ms(s.solved_ttft_ms_p50)],
+ ["LLM call latency p50 (solved tasks)", (s) => ms(s.solved_call_latency_ms_p50)],
+ ["task wall p50 (solved tasks)", (s) => secs(s.solved_task_wall_s_p50)],
+ ["cold start to first call p50 (solved tasks)", (s) => ms(s.solved_cold_start_ms_p50)],
+ ["CPU time / solved task", (s) => secs(s.solved_cpu_seconds_mean)],
+ ["peak RAM, process memory (solved tasks)", (s) => mem(s.solved_peak_anon_mb_max)],
+ ["peak RAM incl. page cache (all tasks)", (s) => mem(s.peak_mem_mb_max)],
+ ["avg RAM (all tasks)", (s) => mem(s.avg_mem_mb_mean)],
+ ["LLM calls (errors)", (s) => `${count(s.llm_calls)} (${count(s.llm_call_errors)})`],
+ ["prompt / completion tokens", (s) => `${count(s.prompt_tokens)} / ${count(s.completion_tokens)}`],
];
const head = `| metric | ${names.join(" | ")} |\n|---|${names.map(() => "---").join("|")}|`;
const body = rows.map(([label, fn]) => `| ${label} | ${names.map((n) => fn(summary[n])).join(" | ")} |`).join("\n");