Repeated runs and variance decomposition
Allocate repetition to independent experimental levels instead of treating every nested timing as a new system execution.
On this page
The question for today
What you’ll understand
- Identify the independent units behind nested benchmark observations.
- Decompose a simple run-level and iteration-level variance model.
- Choose repetition based on uncertainty sources and experimental cost.
A thousand timings collected inside one process do not provide the same evidence as a thousand independently started processes. They share address layout, compilation decisions, machine state, and sometimes a slowly changing background load. Repetition matters at the level where uncertainty arises. A defensible experiment keeps those levels visible and spends its budget on independent units that can change the conclusion, rather than merely producing a large count of correlated measurements.
Write down the nesting before calculating an error bar
Builds can contain executions, and executions can contain timed iterations. Data-center studies may add machines, allocation windows, or clusters above those levels. Record identifiers for each observation’s parents. When a treatment is assigned to an entire process, iterations within that process are not independent treatment assignments. Warmup and steady-state behavior also require a declared policy: discarding initial iterations after inspecting each run’s favorable region can select the answer. Retain the original observations and document any justified stabilization rule.
A simple balanced random-effects model represents one run-specific offset plus independent within-run noise. The run offsets are independent across runs, the residuals are independent across iterations and runs, and the two families are independent. These assumptions are illustrative, not automatic properties of benchmark data. Autocorrelation, machine drift, unequal variances, and heavy tails may require richer models or different estimators. A variance component associated with builds or hosts must be modeled at that level rather than folded into a fictitious independent iteration count.
Reduce the component that dominates uncertainty
Under this balanced model, averaging k iterations reduces within-run noise, but it does not average away the offset shared by all iterations of one run. Independent runs reduce both components in the overall mean. This explains why collecting more iterations in a single process can reach diminishing returns. Pilot measurements can estimate where uncertainty is concentrated, subject to their own sampling error. Use that evidence with startup, rebuild, or allocation costs to plan repetition rather than applying a fixed count to every benchmark.
Allocate independent units to both comparison arms and preserve meaningful pairing when they share inputs or machine-time blocks. Analyze paired differences at the level where pairing actually occurs. For a bootstrap, resample the appropriate independent clusters or use a hierarchy-aware method; resampling individual requests ignores a common run effect. Confidence intervals for a mean do not describe the full latency distribution or the uncertainty of a high percentile. Report the estimand, variance model, unit counts, and method together.
Preserve variation instead of hiding it in a summary
Publish run-level summaries and enough raw data to inspect drift, multimodality, and failures. A minimum execution time may answer a best-case question but cannot silently stand in for a representative mean. Report any exclusions, machine replacements, or unsuccessful starts. If a large allocation permits only a few independent runs, state the resulting limitation rather than multiplying its internal samples into false certainty. Repetition improves precision under an appropriate sampling model; it cannot remove systematic bias shared by every run.
The sampling instrument isolates only independent Bernoulli averaging. Reset, set both p=0.5 and n=25, predict mean 0.5 and standard deviation 0.1 for K/n, then Play or Step. Separately Reset, set both p=0.5 and n=100, predict mean 0.5 and standard deviation 0.05, then Play or Step. The bars are exact probabilities and playback highlights outcomes rather than generating samples. This model has no process offsets, build variability, warmup, or correlated request timings, so its narrowing must not be used as a hierarchical benchmark uncertainty estimate.
Work it through
More runs can beat more iterations
Assume known variance components σ_b²=9 ms² and σ_e²=16 ms². Compare four independent runs with 25 iterations each against ten independent runs with ten iterations each; both collect 100 timings and ignore startup costs for this exercise.
For m=4 and k=25, the grand-mean variance is 9/4+16/100=2.25+0.16=2.41 ms². Its standard deviation is √2.41≈1.5524 ms.
For m=10 and k=10, the variance is 9/10+16/100=0.9+0.16=1.06 ms². Its standard deviation is approximately 1.0296 ms with the same total number of timings.
Keeping only four runs but increasing to 100 iterations each gives 9/4+16/400=2.29 ms². Four times as many timings barely change the dominant run component; an actual budget decision must also include independent-run startup costs.
The number and cost of independent units matter more than a raw observation count when shared run effects dominate.
The living notebook
Explore the model
Interactive lab · sampling
Observe independent averaging without inventing run independence
Reset, set both p=0.5 and n=25, predict mean 0.5 and standard deviation 0.1, then Play or Step. Separately Reset, set both p=0.5 and n=100, predict mean 0.5 and standard deviation 0.05, then Play or Step. Exact iid Bernoulli mean masses do not model nested benchmark variability.
- Mean sample proportion
- 0.5
- Sample-mean variance
- 0.0125
- Uniform CDF error bound
- ≤ 0.1062
Exact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forIncreasing n narrows this independent model; real experiments must justify what counts as n.
Pause & reason
Check your understanding
Your turn
Try it yourself
Under the same known components, calculate the grand-mean variance and standard deviation for nine independent runs with sixteen iterations per run.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use m=9 and mk=144; keep variance in squared milliseconds until the final square root.
Compare with the solution
The variance is 9/9+16/144=1+1/9=10/9 ms². The standard deviation is √(10/9)≈1.0541 ms. This is the model’s sampling standard deviation with known components, not a complete confidence interval fitted from nine observed runs.
Keep the idea
Take it with you
- Keep build, run, machine, and iteration levels visible in the data.
- Allocate repetition where independent variation dominates, including its startup cost.
- A large nested sample count does not establish a large number of independent units.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.