⚙️Benchmark
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
Example code
console
$ python3 -m timeit "sum(range(1000))"
50000 loops, best of 5: 6.69 usec per loopCommon mistake
Key takeaways
- 1Run it many times. Noise averages out.
- 2Compare like with like. Same task, same machine.
- 3Only that task. Not the whole app.