← Math
Math

Confidence, variability, and repeated measurements

Did the build actually get faster?

Distinguish variation in measurements from uncertainty in a benchmark comparison.

Outcome

Name the independent unit, tell spread from standard error, build a band for a paired change, and label it against a margin chosen in advance.

Terminology (6)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Independent unit
The thing that varies independently from one measurement to the next, such as a machine. Repeat runs on one machine are not new units.
Standard deviation Also SD, s
How much individual units vary. The sample form divides squared deviations by n − 1.
Standard error Also SE
Estimated uncertainty of the mean: s / √n. At the same spread, more independent units reduce it.
Approximate 95% band
The lesson’s normal-approximation rule: mean plus and minus two standard errors. With few independent normal units, a95% t interval uses a larger multiplier.
Paired comparison
Measuring each unit before and after and analysing the per-unit differences, so differences between units cancel.
Margin
The smallest change that matters, stated before looking at the data.

Why this matters

Benchmarks, load tests, A/B experiments and latency comparisons are noisy. Deciding from a single run or a raw difference of averages ships regressions and blocks real improvements. A small experiment can establish some things and not others, and saying which depends on counting the right units and using the right kind of spread.

This lesson assumes means and standard deviations from earlier lessons.

Spread and uncertainty answer different questions

Standard deviation describes variation across measured units. Standard error describes how precisely their mean is estimated under a sampling model. The independent unit matters: repeated measurements on one machine do not automatically supply more independent machines. Both quantities use the same units as the measured time, but they answer different questions.

When the same machines run both configurations, pairing forms one after-minus-before change per machine before estimating the mean change and its uncertainty. This lesson uses a fixed, approximate two-standard-error band and a margin chosen before the experiment. The band is a model-based summary, with assumptions about independence and workload stability; it does not establish a guaranteed confidence level or remove systematic timing effects.

01Name the unit

Name the unit

A compiler-flag benchmark recorded build times 4 to 6 ms lower on each of five machines. The dashboard compares the before and after averages, sees machines that differ by 9 ms, and calls the result unclear. Comparing each machine with itself puts the whole change band below the team’s predeclared margin.

The team wants a result across machines and records one per-machine aggregate for each build configuration. Treat machines as independent units under a stable workload; different hardware alone does not prove independence. Balance or randomize before/after order and control warm-up so a shared time trend is not mistaken for a flag effect. Three repeated runs per machine can improve each aggregate, but they do not turn five machine units into fifteen. Shared services or common disturbances can still correlate the machines and weaken the inference.

02Spread of units

Spread of units

Five machines took 102, 98, 101, 99 and 100 ms. Predict the three lines this program prints.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const times = [102, 98, 101, 99, 100]; // ms, one run on each of five machines
const n = times.length;

const mean = times.reduce((sum, x) => sum + x, 0) / n;
const sd = Math.sqrt(times.reduce((sum, x) => sum + (x - mean) ** 2, 0) / (n - 1));
const se = sd / Math.sqrt(n);

console.log(sd.toFixed(2)); // spread across the measured machines
console.log(se.toFixed(2)); // how well five machines pin down the mean
console.log(`${(mean - 2 * se).toFixed(2)} ${(mean + 2 * se).toFixed(2)}`);
Why divide by n − 1 rather than n for the standard deviation?

All numbers are doubles, so squares / (n - 1) divides as expected. Check n before dividing: with one machine n - 1 is 0 and the result is NaN.

03Uncertainty of the mean

Uncertainty of the mean

Five machines, mean 100 ms
QuantityValueAnswers
Standard deviation1.58 msHow much do times vary across machines?
Standard error0.71 msHow well is the mean known?
Mean ± 2 SE98.59 to 101.41Approximate 95% band for the mean
Mean ± 2 SD96.84 to 103.16Scale of individual-machine spread, not uncertainty of the mean

The factor 2 is a normal approximation, not a guaranteed 95% procedure for five units. For independent normal observations with estimated variance, a 95% t interval uses about 2.776 at n = 5, giving a wider interval. The fixed two-SE rule is kept here so the calculation and decision policy are reproducible; it does not repair selection bias, dependence or uncontrolled experiment order. See the NIST confidence-interval formula and t critical values.

04Pair by unit

Pair by unit

After a change the same machines take 99, 95, 98, 96 and 97 ms. Every machine got exactly 3 ms faster: the differences are all −3, their standard deviation is 0 and the band is −3 to −3. Comparing the two groups as if they were different machines gives a standard error of √(0.71² + 0.71²) = 1.0 and a band of −5.0 to −1.0. Both bands are below zero, but only the paired band lies entirely below a −2 ms edge; the unpaired band has width 4 ms while the paired formula collapses to width 0 for these observed identical changes. That collapse does not establish zero uncertainty from timing resolution or shared systematic effects. With noisier machines, an unpaired band can cross the margin even when the paired band does not.

In the opening benchmark, before times 212, 205, 209, 214, 207 ms became 207, 201, 203, 210, 202 ms. The paired changes are −5, −4, −6, −4, −5 ms: mean −4.8 ms, SD ≈ 0.84 ms and SE ≈ 0.37 ms. The two-SE band is −5.55 to −4.05 ms, entirely below the predeclared −2 ms edge. An unpaired calculation instead gives about −9.50 to −0.10 ms and crosses that edge. Matching each before time to its own machine’s after time removes the baseline hardware variation.

Why is the paired band so much narrower?

05Label against the margin

Label against the margin

06Judge the benchmark

Judge the benchmark

Repair the build-results dashboard so it distinguishes variation across machines from uncertainty of the mean. Then use the same machines as their own controls and apply the team’s predeclared margin to the whole paired-change band. Correctly computing two separate group bands still leaves the pairing decision undone.

In the frontend A benchmark card in Next.js and Svelte Optional

A result card shows the change, its band, the margin and the verdict word together, and says that it needs at least two independent machines to estimate this band. A single paired measurement still has a point change, but not a sample SD for this calculation.

Estimate.tsx
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
type Result = { mean: number; low: number; high: number; verdict: string } | null;

// Show the band against the margin, and say when there is too little data to judge.
export function BenchmarkCard({ result, margin }: { result: Result; margin: number }) {
  if (result === null)
    return <p>Need at least two independent machines to estimate this band.</p>;

  return (
    <figure>
      <figcaption>
        Change {result.mean.toFixed(2)} ms (approximate two-SE band{' '}
        {result.low.toFixed(2)} to {result.high.toFixed(2)}), margin ±{margin} ms
      </figcaption>
      <strong>{result.verdict}</strong>
    </figure>
  );
}

Check this idea later
With about the same machine-to-machine spread and independent measurements, increasing from 5 to 20 machines roughly does what to the standard error?
The band for a change is −3.1 to +0.4 ms with a 1 ms margin. What is the verdict?
Sources

Values above were computed in Node 22 and run in Go 1.27, Rust 1.99 and Apple clang 17. The benchmark is a worked model.

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.