Skip to content
BENIBIX Learn

Benchmark

Development⚙️ Compilers & RuntimesPerformance

Also known as Benchmarking, Microbenchmark

A test that measures how fast code runs, so you can compare.

Think of it like

Think of it like timing two routes to school. You walk each one many times, then compare.

Example

Jack has two ways to sort a list. He benchmarks both on 100,000 items. One takes 40 ms, the other 900 ms, so he keeps the first.

Why it matters

Without a number, faster is only a feeling. A benchmark turns it into something you can check.

Definition

A benchmark is a test that measures how fast a piece of code or a system runs. It runs the same task many times and reports a number, like time per run. Running it many times smooths out random noise. You use it to compare two versions, or to check that a change did not make things slower. A benchmark only tells you about the task it runs.

Example code

console
$ python3 -m timeit "sum(range(1000))"
50000 loops, best of 5: 6.69 usec per loop
timeit ran the sum 50,000 times, five rounds over, and reports the best time per run.

Common mistake

Running a test once and trusting the number. One run can be thrown off by anything else on the machine.

Key takeaways

  1. 1
    Run it many times. Noise averages out.
  2. 2
    Compare like with like. Same task, same machine.
  3. 3
    Only that task. Not the whole app.

Compare