// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later // puts render benchmark runs side by side, from what the benchmark copied (see client/benchmark/benchmark.ts) saved // to a file per run. a table for each number, with a column per run and how far each is from the first run // deno run --allow-read tools/compare_benchmarks.ts chrome.md firefox.md ... import { type BenchmarkReport, type MeshingResult, parse_report, type SceneResult, } from "../client/benchmark/report.ts"; const runs = Deno.args.map((path) => ({ path, report: parse_report(Deno.readTextFileSync(path)) })); if (runs.length === 0) { console.error("Give it the files the benchmark's results were saved to"); Deno.exit(1); } if (new Set(runs.map(({ report }) => report.version)).size > 1) { console.warn("These are from different versions of the benchmark, their scenes aren't the same\n"); } const labels = runs.map(({ report }) => `${report.system.browser}, ${report.system.os}`); // each scene once, in the order they ran const scenes = [...new Set(runs.flatMap(({ report }) => Object.keys(report.scenes)))]; const SCENE_NUMBERS: { title: string; value: (scene: SceneResult) => number | undefined }[] = [ { title: "uncapped fps", value: (scene) => scene.uncapped_fps }, { title: "fps", value: (scene) => scene.paced?.fps }, { title: "1% low fps", value: (scene) => scene.paced?.low_1_fps }, { title: "cpu ms per frame", value: (scene) => scene.cpu?.mean_ms }, { title: "gpu ms per frame", value: (scene) => scene.gpu?.mean_ms }, ]; // a value and how far it is from the first run's function cell(value: number | undefined, first: number | undefined, digits: number) { if (value === undefined) return "-"; if (first === undefined || first === 0 || value === first) return value.toFixed(digits); const change = (value / first - 1) * 100; return `${value.toFixed(digits)} (${change > 0 ? "+" : ""}${change.toFixed(0)}%)`; } function table(title: string, rows: [string, (report: BenchmarkReport) => number | undefined][], digits: number) { console.log(`### ${title}\n`); console.log(`| | ${labels.join(" | ")} |`); console.log(`|---|${labels.map(() => "---:").join("|")}|`); for (const [name, value] of rows) { const first = value(runs[0].report); console.log(`| ${name} | ${runs.map(({ report }) => cell(value(report), first, digits)).join(" | ")} |`); } console.log(); } for (const { title, value } of SCENE_NUMBERS) { const digits = title.includes("ms") ? 2 : 1; table(title, scenes.map((name) => [name, (report) => report.scenes[name] && value(report.scenes[name])]), digits); } const chunks_per_second = ({ chunks, ms }: MeshingResult) => chunks / ms * 1000; table("meshing, chunks per second", [ ["first time", (report) => chunks_per_second(report.first_mesh)], ["again", (report) => chunks_per_second(report.remesh)], ], 0); // runs of one version draw about the same, a few chunks can be meshed a frame later, unless something like a mod // differed for (const name of scenes) { const quads = runs.map(({ report }) => report.scenes[name]?.quads ?? 0); if (Math.max(...quads) > Math.min(...quads) * 1.01) { console.warn(`The runs didn't draw the same in ${name}: ${quads.join(", ")} quads`); } } for (const { path, report } of runs) { console.log(`${path}: ${report.system.gpu}, ${report.system.cpu_threads} threads, ${report.mods.join(", ")}`); }