Performance Analysis
When timing a program, why are measurements often repeated with the first few runs discarded?
- AThe first few runs always produce wrong results
- BEarly runs are slow because caches are cold or files are being loaded or code JIT-compiled, and measurements vary
- CRepeating measurements makes the CPU build faster circuits
Show answer and explanation
Answer: B. Early runs are slow because caches are cold or files are being loaded or code JIT-compiled, and measurements vary
On the first run, caches, TLBs and branch predictors start empty, files not yet in the OS cache must be read from disk, and in JIT-compiled languages code is being translated to machine code. So the first few runs are slow. Measurements also vary due to other programs, interrupts and temperature-driven frequency changes, so it is important to measure many times and report the mean or median and the spread.
- A. Results are correct; only the time differs.
- B. Correct. This is called warm-up.
- C. Circuits do not change.