# Benchmark

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

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** Benchmarking, Microbenchmark

## Think of it like

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

## 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

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.

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Profiling](https://learn.benibix.com/term/development/profiling)
- [Cache](https://learn.benibix.com/term/development/cache)
- [Algorithm](https://learn.benibix.com/term/development/algorithm)
- [Big O Notation](https://learn.benibix.com/term/development/big-o-notation)
- [AI Benchmark](https://learn.benibix.com/term/ai/ai-benchmark)
- [Performance Testing](https://learn.benibix.com/term/development/performance-testing)

## Told apart from

- [Profiling vs Benchmark](https://learn.benibix.com/compare/profiling-vs-benchmark): People think a benchmark tells you what to fix, and it does not. A profiler watches a whole program run and shows where the time goes. A benchmark times one piece of code many times, so you can compare two versions. Profile first to find the slow part. Then benchmark the old and new versions of that part.

---

Source: https://learn.benibix.com/term/development/benchmark
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
