Benchmarking
Measuring how fast code runs under controlled conditions, which is far harder to do honestly than it looks.
Benchmarking measures the performance of code, a system, or hardware under controlled, repeatable conditions. A microbenchmark times one small piece of code, such as a sort or a parser, in a tight loop. A macrobenchmark times a realistic workload end to end. Either way, the goal is a number that reflects reality well enough to compare two versions, and getting there is full of traps.
The common ways a benchmark lies:
- Warmup. The first runs are slow while caches fill, JIT compilers optimize hot code, and lazy initialization happens. Measuring them reports startup cost, not steady-state speed. Measuring only after warmup hides the startup cost that real users may pay. Which matters depends on the question.
- Dead code elimination. If the benchmark never uses a result, an optimizing compiler may delete the computation entirely and report a miraculous speedup. Benchmark harnesses provide a way to consume results to prevent this.
- Noise. CPU frequency scaling, Thermal Throttling, background processes, and the CPU Scheduler add variance. A single run means little. Results need repetition, a distribution, and a confidence interval. A 2% "improvement" inside 5% noise is nothing.
- Unrepresentative inputs. Sorting already-sorted data, hitting a warm cache, or using toy sizes where everything fits in L1 cache. Big-O Notation predicts growth, but constants, memory access patterns, and cache effects decide real speed at real sizes.
- Measuring the harness. Timer overhead and loop bookkeeping can outweigh very fast code.
Benchmarks drive decisions, so they attract optimization aimed at the score rather than real use. GPU drivers and phones have been caught detecting benchmark programs and changing behavior for them. Machine learning leaderboards suffer when models are tuned against fixed test sets, a form of Overfitting. This is Goodhart's Law in a lab coat: once a benchmark becomes the target, it stops measuring general performance.
Used well, benchmarks catch performance regressions in Continuous Integration the way tests catch functional ones, by tracking results over time and flagging significant changes. They also keep optimization honest. Premature Optimization is often optimization without measurement, and a profiler shows where time actually goes before a benchmark confirms the fix helped. Performance Budget targets for web pages are benchmarks expressed as limits. Frame Pacing shows the general lesson: averages hide the stutter, and percentiles reveal it.
See also3
Graphics Driver
The software that translates a program's drawing commands into instructions a particular graphics card can execute, split between a kernel part that manages memory and displays and a large user-space part that compiles shaders and implements graphics interfaces.
Systems & Tooling17 connections
Page Cache
The operating system's use of spare memory to hold recently read and written file data, which makes repeated disk access fast and makes "free memory" look alarmingly low.
Systems & Tooling11 connections
Microcode
The updatable firmware inside a processor that controls how it executes instructions, how operating systems load patches into it at every boot, and the hardware bugs it has been used to fix.
Systems & Tooling7 connections
Linked from6
- Confidence IntervalMethod
A range around an estimate that conveys how precisely it was measured, more informative than a yes-or-no significance verdict, and easy to misread as a statement of probability about the true value.
- Graphics DriverSystems & Tooling
The software that translates a program's drawing commands into instructions a particular graphics card can execute, split between a kernel part that manages memory and displays and a large user-space part that compiles shaders and implements graphics interfaces.
- MicrocodeSystems & Tooling
The updatable firmware inside a processor that controls how it executes instructions, how operating systems load patches into it at every boot, and the hardware bugs it has been used to fix.
- Page CacheSystems & Tooling
The operating system's use of spare memory to hold recently read and written file data, which makes repeated disk access fast and makes "free memory" look alarmingly low.
- Performance BudgetWeb Platform
A committed numeric ceiling on a page's cost, enforced automatically.
- Premature OptimizationMethod
Spending effort making code fast before you know where it's actually slow trades clarity for speed you may not need.