#!/usr/bin/env node // BudgetBench TURN COSTS of one run, aggregates only (safe on a sealed run: no case id, question, answer or label): // seconds per turn (median, 90th percentile), the reader call's own seconds when the run recorded them, and the most // process memory any turn saw (systems/pulse-local.mjs records rssMB on every turn since 2026-10-22). // node budgetbench/stats/turns.mjs import fs from "node:fs"; import path from "node:path"; const dir = process.argv[2]; if (!dir) { console.error("usage: turns.mjs "); process.exit(2); } const rows = fs.readFileSync(path.join(dir, "results.jsonl"), "utf8").split("\n").filter(Boolean).map((l) => JSON.parse(l)); const turns = rows.flatMap((r) => r.turns ?? []); const q = (xs, p) => { const s = [...xs].sort((a, b) => a - b); return s.length ? s[Math.min(s.length - 1, Math.floor(p * s.length))] : null; }; const ms = turns.map((t) => t.meta?.ms).filter((x) => typeof x === "number"); const rms = turns.flatMap((t) => (t.meta?.reader ?? []).map((c) => c.ms)).filter((x) => typeof x === "number"); const rss = turns.map((t) => t.meta?.rssMB).filter((x) => typeof x === "number"); const sec = (x) => (x == null ? null : Math.round(x / 10) / 100); console.log(JSON.stringify({cases: rows.length, turns: turns.length, turn_s_median: sec(q(ms, 0.5)), turn_s_p90: sec(q(ms, 0.9)), reader_calls: rms.length, reader_s_median: sec(q(rms, 0.5)), reader_s_p90: sec(q(rms, 0.9)), rss_mb_max: rss.length ? Math.max(...rss) : null}));