Skip to content
Tactiverge

School/□ Systems Engineer/Week 34

Designing a benchmark you can trust

The new version is 1.6× faster. Or the first runs were cold, the laptop was heating up and the test file was smaller. Which?

About 45 min · 3 goals · Checked by automated tests

1.Why should I care?

The term project asks you to prove an optimisation worked. A benchmark is an experiment: it can be fair or rigged, precise or noisy. Most surprising speed-ups in the wild come from methodology, not from the code.

  • ◇ Design a benchmark with warm-up, repeats, matched inputs and interleaved runs.
  • ◇ Identify bias from cold starts, drift and unequal workloads in timing data.
  • ◇ Pre-define the metric, the baseline and the decision rule before running.

2.Discover

Fix the problems one at a time and watch the speed-up and its interval after each: same input, then interleaved order, then 3 warm-up runs, then 30 repeats. Which fix moved the estimate most? Which narrowed the interval most? Re-run with new seeds to see the interval jitter.

Loading the interactive…

Can't use the interactive? Read a description instead

The checker simulates per-run times for a baseline A (true 40 ms) and version B (true 31 ms on the same input, 24 ms on a smaller one), with cold-start penalties on the first three runs of each version, a slow upward drift over the session, and random noise. It plots runs in order and reports each mean with a 95% interval, the speed-up with its interval, and a checklist: warm-up of at least 3 runs, at least 10 repeats, interleaved order and the same input. Fixing all four gives speed-ups close to the true 1.29.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

Why discard the first few runs of a steady-state benchmark?

4.Predict

The checker starts with 5 repeats, no warm-up, blocked order and B on a smaller input. Will the measured speed-up be too high, too low, or about right?

Guess first. Being wrong here is how the surprise works.

5.Understand

Decide before you measure

Write down the metric (median wall time per run? energy per job?), the workload (input files, sizes), the baseline (current release, built the same way), the environment (machine, power mode, other processes), the number of repeats and the decision rule ('ship if the 95% interval on speed-up is above 1.1'). Deciding afterwards invites choosing whatever looks best.

Warm-up and steady state

First runs pay for empty caches, page faults, JIT compilation and frequency ramp-up. Unless cold-start performance is what you care about (an app's launch time), discard a few warm-up runs and report steady-state. If it is what you care about, measure it deliberately with a fresh process each time.

Repeats and variance

Timing noise comes from interrupts, scheduling, thermal throttling and memory layout. Repeat enough to make the standard error small compared with the effect you care about, and report spread, not just the mean. Medians and percentiles are robust to occasional slow runs; say which you use.

Fair comparison

Same input, same build flags, same machine, same conditions. Interleave versions (A, B, A, B…) or randomise their order so slow drift affects both equally. Pin CPU frequency if you can, close other programs, and note what you couldn't control. A fair benchmark is one where the only systematic difference is the change under test.

Explain it another way

Racing two runners is unfair if one starts cold, one runs downhill, or one runs a shorter track. A benchmark is a race; make the track the same.

Worked example 1

Blocked order: A runs first for 13 runs, then B for 13. The machine slows by 0.12 ms per run. Estimate the bias in B's mean.

A's runs occur on average at position 6.5, B's at 19.5: 13 positions later. Bias ≈ 13 × 0.12 = 1.56 ms added to B, making B look slower than it is. Interleaving would cut this to about 0.06 ms.

Common mix-ups

  • Running the benchmark once on each version is enough if the difference is big.
    ✓ Big differences often come from methodology (cold starts, unequal inputs). Repeats and fair conditions are needed to trust any size of effect.
  • The best run shows the true performance.
    ✓ Best-of-n is biased optimistic and noisy. Report a centre (median or mean) with its uncertainty.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

Why interleave runs of A and B rather than running all A then all B?

Practice 3 · a fresh version every time

After warm-up, the baseline takes a mean of 24 ms per run and the optimised version 13.3 ms (same machine, same input, interleaved runs). What is the speed-up, baseline time ÷ new time? (3 significant figures.)

×

Practice 4 · a fresh version every time

Past runs of a benchmark have mean 72 ms and standard deviation 5 ms. A new run takes 88 ms. What is its z-score? (2 decimal places; negative if it is below the mean.)

Practice 5

Which decision rule is best written before running the benchmark?

7.Apply it

Write a one-page benchmark protocol for your term project: metric, workload, baseline, environment, warm-up, repeats, order, statistics and decision rule. Get a classmate to find one way your protocol could still be unfair.

8.Reflect

9.Go further

Research mode: limits and open questions

Benchmark results that can't be reproduced are a recognised problem across computing research; artefact evaluation, in which reviewers re-run a paper's experiments from its published code, is one response.

    Concepts: Benchmarking methodology · Baselines and ablation studies · Evaluation metrics