Compare two Python environments: a first run
Write a workload that prints its timings, run pairbench run with two sides, and read the
verdict of each case; this page does it for two Python environments and then puts a number from
the results into a document.
-
Install pairbench, with the tool you use for Python programs:
pip install pairbenchuv tool install pairbenchpipx install pairbench -
Write a workload. Any command can be a workload. A workload that times itself and prints its timings lets pairbench leave the start of the process out; here the script prints one line per case for the
linesdriver:import jsonimport timestart = time.perf_counter()total = sum(i * i for i in range(2_000_000))elapsed = time.perf_counter() - startprint("::pairbench::", json.dumps({"case": "squares", "value": elapsed, "unit": "s"}))Save it as
bench.py. -
Print the plan.
pairbench plan --side new=venv:.venv-new --side old=venv:.venv-old --driver lines -- python bench.pyThe plan prints the lineup, each side followed by its twin (
new~same,old~same), the positive control (old~twice), the round count, the launches and the balance of every pair. It launches nothing. -
Run it.
pairbench run --side new=venv:.venv-new --side old=venv:.venv-old --driver lines -- python bench.pyExample output (made-up numbers):
new against old (baseline)case new old change noise p verdictsquares 0.141 s 0.152 s 1.08x faster ±1.5% 0.00052* FASTERExact two-sided sign test over 16 paired rounds.* one case tested.Rule: strict.Machine state: quiet.Baseline: old.Positive control old~twice: ok.What each part says:
- change: the median of the per-round ratios, written as “x faster” or “x slower”.
- noise: the bar the gap had to exceed, the sum of both sides’ noise floors measured from their twins.
- p: the exact sign test’s p-value, corrected for the number of cases tested.
- verdict: FASTER, SLOWER, TIE, UNRESOLVED or NO VERDICT. See verdicts.
- footer: the rounds, the rule, the machine state, the baseline and the positive control.
The run folder,
pairbench-runs/<time>-<id>/, holdscapture.jsonl(the raw record),results.json(the analysed document),results.md,plan.tsv,report.html,artifacts/(what each launch printed and the files its tool wrote), and, when the explain step ran,diagnostics.jsonandprofiles/. -
Put a number into a document. Write a template with figure tokens:
On this machine, new ran {{fig:squares.new_vs_old.speedup}} the speed of old({{fig:squares.new_vs_old.verdict}}, noise {{fig:squares.new_vs_old.bar}}).and fill it from the results:
pairbench fill notes.in.md --results pairbench-runs/RUN/results.json -o notes.mdEvery token is replaced by the text of its figure. A missing figure stops the command with exit code 7 and lists every missing key. In an automated pipeline,
pairbench fill ... --checkexits 1 when the document differs from what its results give.
- Compare container images:
--side new=image:REF --side old=image:REF. - Run on a shared machine: shared machines.
- Check a pull request for slowdowns:
--fail-on worsemakes the exit code 1 when a primary case comes out worse. - Read the command reference.
pairbench is made by Eugo