import { TriangleAlertIcon } from "lucide-react"; import { BenchmarkResources } from "@/components/benchmark-resources"; import { abCaveats, abHeadline, abMethod, abSummaryText, halfWidth } from "@/lib/ab-report"; import { CONFIG_ROWS } from "@/lib/benchmark-view"; import type { PairedResult } from "@/lib/db/schema"; import { cn } from "@/lib/utils"; import type { ListRow } from "../benchmark-list"; const sign = (v: number) => `${v > 0 ? "+" : ""}${v.toFixed(2)}%`; /** The difference with its 95% interval on a %-axis: zero line, the ±target band, the interval and the point. */ function IntervalChart({ r, target }: { r: PairedResult; target: number }) { const reach = Math.max(Math.abs(r.ci_low_pct), Math.abs(r.ci_high_pct), target) * 1.25 || 1; const pos = (v: number) => `${((v + reach) / (2 * reach)) * 100}%`; const ticks = [-reach, -reach / 2, 0, reach / 2, reach].map((t) => Math.round(t * 10) / 10); return (
{/* ±target band: differences inside it are smaller than the precision asked for */}
{ticks.map((t) => ( {t > 0 ? "+" : ""} {t}% ))}

Dot: B's difference from A. Bar: the 95% interval. Grey band: ±{target}%, the precision asked for. B is better to the {r.higher_is_better ? "right" : "left"}.

); } function Side({ label, name, value, unit }: { label: string; name: string; value: number; unit: string }) { return (
{label} {value.toFixed(unit === "ms" ? 2 : 1)} {unit} {name}
); } export function AbReport({ run }: { run: ListRow }) { const ab = run.ab; const a = run.snapshot; const b = run.snapshotB; if (!ab || !b) return null; const d = ab.decode_tps; const g = ab.gap_median; const caveats = abCaveats(ab); const rows = CONFIG_ROWS.map((row) => ({ row, va: row.value(a), vb: row.value(b) })).filter((x) => x.va != null || x.vb != null); const differs = rows.filter((x) => x.va !== x.vb); const same = rows.filter((x) => x.va === x.vb); return (
BetterBench {ab.betterbenchVersion} · paired A/B · {ab.pairs} pairs

{run.label ?? `${a.deploymentName} vs ${b.deploymentName}`}

{abSummaryText(ab, a.deploymentName, b.deploymentName)}

Decode throughput {abHeadline(d)} {sign(d.pct_diff)} · 95% CI {sign(d.ci_low_pct)} to {sign(d.ci_high_pct)} · {d.significant ? "significant" : "within noise"}
{g.batched ? "Stream-update gap" : "Token-to-token smoothness"} {abHeadline(g)} {sign(g.pct_diff)} · 95% CI {sign(g.ci_low_pct)} to {sign(g.ci_high_pct)} · lower is better
Pairs {ab.pairs} ±{halfWidth(d).toFixed(2)}% reached · target ±{ab.target_mde_pct}%
Paired CV {(ab.paired_cv * 100).toFixed(2)}% ~{ab.pairs_needed_for_mde} pairs for ±{ab.target_mde_pct}%
{caveats.length > 0 && (
Read these first {caveats.map((x) => (

{x}

))}
)}

What differs

{differs.length === 0 && ( )} {differs.map(({ row, va, vb }) => ( ))}
A · {a.deploymentName} B · {b.deploymentName}
Same settings on both sides (a null A/B: it shows how much noise the setup has).
{row.label} {va ?? default} {vb ?? default}
{same.length > 0 &&

Same on both: {same.map((x) => `${x.row.label.toLowerCase()} ${x.va}`).join(" · ")}.

}
{run.resources && (

Resources

)}

Method

{abMethod(ab).map((p) => (

{p}

))}
); }