bench / report.ts
bench / report.ts
/** Benchmark result rendering: markdown + JSON, stamped and comparable. */
import { PromptVariant } from "../src/summarizer";
import { StructuralReport } from "./metrics";
export interface FixtureResult {
fixture: string;
asked: number;
correctAfterCompaction: number;
correctAfterConsolidation?: number;
reductionPercent: number;
latency: { mean: number; p50: number; max: number };
structural: StructuralReport;
cacheDeterministic: boolean;
}
export interface BenchRun {
date: string;
modelId: string;
/** Summarizer prompt variant benched (see bench/run.ts's --variant flag). Omitted/undefined means "full", the default. */
variant?: PromptVariant;
settings: Record<string, unknown>;
fixtures: FixtureResult[];
}
export function renderMarkdown(run: BenchRun): string {
const lines: string[] = [
`# context-compressor benchmark — ${run.date}`,
"",
`Model: \`${run.modelId}\``,
"",
...(run.variant !== undefined && run.variant !== "full"
? [`Variant: \`${run.variant}\``, ""]
: []),
`Settings: \`${JSON.stringify(run.settings)}\``,
"",
"| Fixture | Recall (compacted) | Recall (consolidated) | Reduction | Chunk latency mean/p50/max (ms) | Structure | Cache |",
"|---|---|---|---|---|---|---|",
];
for (const f of run.fixtures) {
const consolidated =
f.correctAfterConsolidation !== undefined
? `${f.correctAfterConsolidation}/${f.asked}`
: "—";
lines.push(
`| ${f.fixture} | ${f.correctAfterCompaction}/${f.asked} | ${consolidated} | ${f.reductionPercent}% | ${f.latency.mean}/${f.latency.p50}/${f.latency.max} | ${f.structural.ok ? "✅" : "❌"} | ${f.cacheDeterministic ? "✅" : "❌"} |`,
);
}
lines.push(
"",
"Recall = seeded facts answered correctly from the compacted view alone. " +
"Results are comparable only within one model; see bench/README.md.",
);
return lines.join("\n");
}
/**
* e.g. "2026-08-20-qwen-qwen3.8-27b" — filesystem-safe. Non-"full" variants
* get a suffix (e.g. "-compact") so runs against a different prompt variant
* never overwrite the default run's result files.
*/
export function resultFileBase(run: BenchRun): string {
const model = run.modelId.replace(/[^a-z0-9.-]+/gi, "-");
const variantSuffix =
run.variant !== undefined && run.variant !== "full" ? `-${run.variant}` : "";
return `${run.date}-${model}${variantSuffix}`;
}
/** Benchmark result rendering: markdown + JSON, stamped and comparable. */
import { PromptVariant } from "../src/summarizer";
import { StructuralReport } from "./metrics";
export interface FixtureResult {
fixture: string;
asked: number;
correctAfterCompaction: number;
correctAfterConsolidation?: number;
reductionPercent: number;
latency: { mean: number; p50: number; max: number };
structural: StructuralReport;
cacheDeterministic: boolean;
}
export interface BenchRun {
date: string;
modelId: string;
/** Summarizer prompt variant benched (see bench/run.ts's --variant flag). Omitted/undefined means "full", the default. */
variant?: PromptVariant;
settings: Record<string, unknown>;
fixtures: FixtureResult[];
}
export function renderMarkdown(run: BenchRun): string {
const lines: string[] = [
`# context-compressor benchmark — ${run.date}`,
"",
`Model: \`${run.modelId}\``,
"",
...(run.variant !== undefined && run.variant !== "full"
? [`Variant: \`${run.variant}\``, ""]
: []),
`Settings: \`${JSON.stringify(run.settings)}\``,
"",
"| Fixture | Recall (compacted) | Recall (consolidated) | Reduction | Chunk latency mean/p50/max (ms) | Structure | Cache |",
"|---|---|---|---|---|---|---|",
];
for (const f of run.fixtures) {
const consolidated =
f.correctAfterConsolidation !== undefined
? `${f.correctAfterConsolidation}/${f.asked}`
: "—";
lines.push(
`| ${f.fixture} | ${f.correctAfterCompaction}/${f.asked} | ${consolidated} | ${f.reductionPercent}% | ${f.latency.mean}/${f.latency.p50}/${f.latency.max} | ${f.structural.ok ? "✅" : "❌"} | ${f.cacheDeterministic ? "✅" : "❌"} |`,
);
}
lines.push(
"",
"Recall = seeded facts answered correctly from the compacted view alone. " +
"Results are comparable only within one model; see bench/README.md.",
);
return lines.join("\n");
}
/**
* e.g. "2026-08-20-qwen-qwen3.8-27b" — filesystem-safe. Non-"full" variants
* get a suffix (e.g. "-compact") so runs against a different prompt variant
* never overwrite the default run's result files.
*/
export function resultFileBase(run: BenchRun): string {
const model = run.modelId.replace(/[^a-z0-9.-]+/gi, "-");
const variantSuffix =
run.variant !== undefined && run.variant !== "full" ? `-${run.variant}` : "";
return `${run.date}-${model}${variantSuffix}`;
}