import type { Metadata } from "next"; import Link from "next/link"; import { BenchmarkStateBadge } from "@/components/benchmark-state"; import { Card } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { getBenchmarks } from "@/lib/benchmarks"; import { metaRows } from "@/lib/benchmark-meta"; import { SECTION_LABEL } from "@/lib/quality-view"; import { CONFIG_ROWS, deltaPct, describeSettings, headline, targetName } from "@/lib/benchmark-view"; import type { BenchmarkSummary } from "@/lib/db/schema"; import { cn } from "@/lib/utils"; export const dynamic = "force-dynamic"; export const metadata: Metadata = { title: "Compare benchmarks" }; type Metric = { label: string; unit: string; higherIsBetter: boolean; digits: number; get: (s: BenchmarkSummary | null, runIndex?: number) => number | null }; /** Differences smaller than this are shown without color: below what a single run can resolve. */ const NOISE_PCT = 2; function Delta({ v, base, higherIsBetter }: { v: number | null; base: number | null; higherIsBetter: boolean }) { const d = deltaPct(v, base); if (d == null) return null; const good = higherIsBetter ? d > 0 : d < 0; return ( {d > 0 ? "+" : ""} {d.toFixed(1)}% ); } export default async function ComparePage({ searchParams }: PageProps<"/benchmarks/compare">) { const { ids } = await searchParams; const runs = await getBenchmarks( String(ids ?? "") .split(",") .filter(Boolean) .slice(0, 16), ); if (runs.length < 2) { return (

Pick at least two completed runs on the{" "} Benchmarks {" "} page.

); } const sums = runs.map((r) => r.summary); const depths = [...new Set(sums.flatMap((s) => s?.prefill.filter((p) => !p.skipped).map((p) => p.target_depth) ?? []))].sort((a, b) => a - b); const levels = [...new Set(sums.flatMap((s) => s?.concurrency.map((c) => c.level) ?? []))].sort((a, b) => a - b); const categories = [...new Set(sums.flatMap((s) => s?.single.map((c) => c.category) ?? []))]; const groups: { group: string; rows: Metric[] }[] = [ { group: "Headline", rows: [ { label: "Prefill (deepest prompt)", unit: "t/s", higherIsBetter: true, digits: 0, get: (s) => headline(s).prefill?.tps ?? null }, { label: "Decode (weighted)", unit: "t/s", higherIsBetter: true, digits: 1, get: (s) => headline(s).decode }, { label: "Time to first token", unit: "ms", higherIsBetter: false, digits: 0, get: (s) => headline(s).ttftMs }, ], }, { group: "Decode per category", rows: categories.map((c) => ({ label: c, unit: "t/s", higherIsBetter: true, digits: 1, get: (s) => s?.single.find((x) => x.category === c)?.decode_med ?? null })), }, { group: "Prompt processing", rows: depths.map((d) => ({ label: `${d.toLocaleString()} tokens`, unit: "t/s", higherIsBetter: true, digits: 0, get: (s) => s?.prefill.find((p) => p.target_depth === d && !p.skipped)?.pp_med ?? null, })), }, { group: "Parallel requests (total)", rows: levels.map((l) => ({ label: `${l} parallel`, unit: "t/s", higherIsBetter: true, digits: 1, get: (s) => s?.concurrency.find((c) => c.level === l)?.aggregate_tps ?? null })), }, ]; // Quality evals: the score and each section's pass rate (only when some of the runs are evals). const quality = runs.map((r) => r.quality); if (quality.some(Boolean)) { const sections = [...new Set(quality.flatMap((q) => q?.sections.map((s) => s.section) ?? []))]; groups.push({ group: `Quality (${[...new Set(quality.filter(Boolean).map((q) => q!.evalSet))].join(", ")})`, rows: [ { label: "Score", unit: "%", higherIsBetter: true, digits: 1, get: (_s, i) => quality[i!]?.score ?? null }, ...sections.map((sec) => ({ label: SECTION_LABEL[sec], unit: "%", higherIsBetter: true, digits: 1, get: (_s: BenchmarkSummary | null, i?: number) => quality[i!]?.sections.find((x) => x.section === sec)?.score ?? null, })), ], }); } const metrics = groups.filter((g) => g.rows.length > 0); // Hardware, runtime version, model/quant/KV, context and concurrency as recorded at the start of each run. const metaByRun = runs.map((r) => (r.meta ? metaRows(r.meta) : null)); const metaKeys = [...new Map(metaByRun.flatMap((rows) => rows ?? []).map((x) => [x.key, x.label])).entries()]; const metaTable = metaKeys.map(([key, label]) => ({ key, label, values: metaByRun.map((rows) => (rows ? (rows.find((x) => x.key === key)?.value ?? null) : null)) })); const configRows = CONFIG_ROWS.map((row) => ({ row, values: runs.map((r) => row.value(r.snapshot)) })).filter((x) => x.values.some((v) => v != null)); const corpora = new Set(sums.map((s) => s?.corpusVersion).filter(Boolean)); const anyQuick = runs.some((r) => r.summary?.quick); return (

Compare benchmarks

Differences are against the first run. Separate runs aren't paired in time, so differences below ~{NOISE_PCT}% are within normal noise.

{corpora.size > 1 &&

These runs used different prompt sets (corpus versions), so their numbers aren't comparable.

} {anyQuick &&

Some runs are quick runs (5 passes); their numbers are rough.

}
{runs.map((r, i) => ( {r.label ?? targetName(r.snapshot)}
{i === 0 && baseline}
{describeSettings(r.settings)}
))}
{metaTable.length > 0 && ( <> Hardware & runtime {metaTable.map(({ key, label, values }) => { const differs = new Set(values.map((v) => v ?? "")).size > 1; return ( {label} {values.map((v, i) => ( 0 && v !== values[0] && "text-amber-700 dark:text-amber-300")}> {v ?? not recorded} ))} ); })} )} Settings {configRows.map(({ row, values }) => { const differs = new Set(values.map((v) => v ?? "")).size > 1; return ( {row.label} {values.map((v, i) => ( 0 && v !== values[0] && "text-amber-700 dark:text-amber-300")}> {v ?? default} ))} ); })} {metrics.map((g) => ( ))}
); } function MetricGroup({ group, rows, sums, cols }: { group: string; rows: Metric[]; sums: (BenchmarkSummary | null)[]; cols: number }) { return ( <> {group} {rows.map((m) => { const vals = sums.map((s, i) => m.get(s, i)); const present = vals.filter((v): v is number => v != null); const best = present.length > 1 ? (m.higherIsBetter ? Math.max(...present) : Math.min(...present)) : null; return ( {m.label} {vals.map((v, i) => ( {v == null ? ( – ) : ( <> {v.toFixed(m.digits)} {m.unit} {i > 0 && } )} ))} ); })} ); }