Routing reference test runs on today's routing loop; perf bench reads exported saves

The reference test from #106 now patches the loop as it looks after #96
(business-first passes) and also covers prefer, prepend and protect
customers. It catches an exit index that ignores RouteScript preferences,
which the shortcut test in speed.test.js cannot see.

npm run perf -- --save accepts files from the in-game Export save, so
scripts/benchmark-performance.js and its README section are not needed.
The performance skill documents --save, both equivalence tests and how to
handle noisy runs.
This commit is contained in:
Frederic Jung 2026-10-26 08:40:20 +01:00
parent 2366bb9a8f
commit e5deb90968
No known key found for this signature in database
6 changed files with 22 additions and 63 deletions

View file

@ -1,43 +0,0 @@
#!/usr/bin/env node
// Headless CPU/DOM benchmark, not a browser frame-rate measurement.
// node scripts/benchmark-performance.js SAVE.json [BASELINE.html]
// git show main:site/index.html > /tmp/tubes-baseline.html
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert/strict');
const { load } = require('../tests/harness');
const [saveFile, baseline] = process.argv.slice(2);
if (!saveFile) {
console.error('Usage: node scripts/benchmark-performance.js SAVE.json [BASELINE.html]');
process.exit(1);
}
const input = JSON.parse(fs.readFileSync(saveFile, 'utf8'));
const save = input.S || input;
function benchmark(file) {
const { ev, dom, errors } = load({ file });
try {
ev('ACT.start({})');
dom.window.benchmarkSave = JSON.parse(JSON.stringify(save));
ev('S=migrate(window.benchmarkSave);UI.speed=0;innerWidth=390;innerHeight=844;compute()');
const result = JSON.parse(ev('JSON.stringify(R)'));
const measure = (setup, run, repeats) => {
ev(setup);
const samples = JSON.parse(ev(`(()=>{const out=[];for(let i=0;i<${repeats};i++){const start=performance.now();${run};out.push(performance.now()-start);}return JSON.stringify(out);})()`));
const sorted = [...samples].sort((a, b) => a - b);
return { medianMs: +sorted[Math.floor(sorted.length / 2)].toFixed(1), samplesMs: samples.map(v => +v.toFixed(1)) };
};
const timings = {
compute: measure('', 'compute()', 5),
closedNetworks: measure("UI.left='nets';UI.leftOpen=false;UI.sel=null", 'renderLeft()', 3),
openConnections: measure("UI._dh=null;UI.dtab='conn'", 'ACT.connOpen()', 1),
action: measure("$('dash').hidden=true;UI.leftOpen=false;UI.left='nets'", 'after()', 3),
};
assert.deepEqual(errors, []);
return { result, timings };
} finally { dom.window.close(); }
}
const original = baseline ? benchmark(path.resolve(baseline)) : null;
const current = benchmark(path.join(__dirname, '..', 'site', 'index.html'));
if (original) assert.deepEqual(current.result, original.result, 'Simulation output must match the baseline');
console.log(JSON.stringify({ baseline: original?.timings, current: current.timings, ...(original && { identicalSimulation: true }) }, null, 2));

View file

@ -4,6 +4,7 @@
// node scripts/perf-bench.js time this checkout
// node scripts/perf-bench.js --base OLD.html compare OLD.html (e.g. main) with this checkout
// node scripts/perf-bench.js --base OLD.html --md out.md --summary "$GITHUB_STEP_SUMMARY"
// node scripts/perf-bench.js --save my-export.json --base OLD.html a player's save (plain or exported from the menu)
//
// Both versions load the same save in one process and are timed in alternating turns, so a busy machine slows
// them equally. Each number is the median of several runs. It also says whether both versions route the save's
@ -19,7 +20,9 @@ const ROOT = path.join(__dirname, '..');
const HEAD = opt('--head', path.join(ROOT, 'site', 'index.html'));
const BASE = opt('--base', null);
const RUNS = +opt('--runs', 7);
const SAVE = fs.readFileSync(opt('--save', path.join(ROOT, 'tests', 'fixtures', 'big-network.json')), 'utf8');
// A plain save, or a file from the in-game "Export save", which wraps it as {app, version, exported, S}.
const RAW = JSON.parse(fs.readFileSync(opt('--save', path.join(ROOT, 'tests', 'fixtures', 'big-network.json')), 'utf8'));
const SAVE = JSON.stringify(RAW && RAW.app === 'series-of-tubes' && RAW.S ? RAW.S : RAW);
// What we time. Each body runs inside the game page; panels flip between two selections so nothing can be
// skipped as "unchanged".