ac-bench
How-to guides

How-to guide

Catch a regression against a baseline

Record a run before a change, compare the run after it, and fail when a case got slower than you allow.

Before you start. A suite that runs with measure -c bench.config.ts, and the commit to compare against checked out.

1. Record the run before the change

On the commit you compare against, run the suite once with --save-baseline. A name files the archive under this machine’s fingerprint, so it is never compared with another machine’s run by accident.

Terminal
git switch mainnpx measure -c bench.config.ts --save-baseline main

The archive lands in node_modules/.cache/ac-bench/baselines/<fingerprint>/main.json. The fingerprint is a short hash of what a direct comparison requires equal: CPU model, logical cores, architecture, OS, mode, and each runtime’s product, major version and flags.

2. Make the change

Edit, build, switch branch — anything that does not change the machine, the Node major version, its flags or the mode. Those make up the fingerprint: changing one makes the baseline incomparable.

3. Compare, with the regression you allow

--max-regression 0.03 gives every case present in both runs a gate now / baseline ≤ 1.03. It fails only when the whole interval is above the threshold, so noise alone does not fail it.

Terminal
npx measure -c bench.config.ts --baseline main --max-regression 0.03

Exit status 2 means undecided: the interval straddles 1.03. Run again with --mode rigorous to buy executions, or accept it in a quick local check with --allow-inconclusive.

4. Keep the threshold in the config

bench.config.ts
export default defineConfig({
  plugins: [durationPlugin],
  baseline: { maxRegression: 0.03 },
});

Now npx measure -c bench.config.ts --baseline main is enough; the flag still wins over the file.

Variations

Compare with a baseline from another machine

Commit the archive and pass it as a path: a value with a / or ending in .json. Name a case every comparison is divided by — baseline.normalizeBy — and add --allow-foreign-baseline: the double ratio (case / normalizer) now ÷ (case / normalizer) then cancels machine speed to first order.

Terminal
npx measure -c bench.config.ts --baseline baselines/ci.json --allow-foreign-baseline

Exit 4, “incomparable”

The baseline’s fingerprint differs: another CPU, Node major, flag set or mode.

Every comparison is inconclusive

A baseline saved with --mode quick holds one execution per case, which says nothing about the spread. Save baselines in standard or rigorous mode.