# Why Your Micro Benchmarks Should Run for 300 Milliseconds

Original title: Benchmark in Milliseconds

> Hacker News story 49967427 · language: en · submitted 2026-10-05
> Web version: https://zeli.app/story/49967427
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 145 · by [surprisetalk](<https://news.ycombinator.com/user?id=surprisetalk>) · 💬 53
[original](<https://matklad.github.io/2026/10/05/benchmark-milliseconds.html>) · [HN discussion](<https://news.ycombinator.com/item?id=49967427>)

## Summary

A simple rule of thumb: tweak input size until a micro benchmark takes about 300ms. Milliseconds are easy to scan, avoid floating-point units, and are long enough to make fixed costs like interpreter startup irrelevant. Hundreds of milliseconds also sit in the human-perceptible range, so you can feel whether an optimization turned a lagging CLI command into something instant. Anything longer than a second just slows iteration, and the real goal is intuition, not precision.

## Key quote

> The imminently-to-be-stated assumption here is that the purpose of benchmarking isn’t so much a precise measurement of performance, but rather providing the author with enough intuition to make a correct decision.

## HN discussion (53 comments)

### [spankalee](<https://news.ycombinator.com/item?id=49981209>)

> I would rather say: "benchmark with confidence intervals" or maybe "benchmark with comparisons".
>
> It's very hard to say much about an absolute number. You need to compare against some alternative or control, and because of CPU load, throttling, GC, and a thousand other variables, you really should be comparing against that control _in the same run_, and importantly round robin across multiple runs to spread out the noise fairly across each implementation.
>
> Then once you have a bunch of measurements you have a distribution and shouldn't just take a mean to compare, but should calculate something like the 95% confidence interval. If you see that those confidence intervals overlap, the you might not really know which is faster. If they don't overlap, then you probably do know which is faster.
>
> If you have a good benchmark, then running it more times can narrow the confidence intervals and let you tease out very small improvements at the cost of longer runs. If confidence intervals don't narrow, then you hit the limits of signal-to-noise.
>
> This is the only way I've been able to get reliable, actionable benchmarks outside of a very, very controlled hardware lab. It's what Google's Tachometer benchmark runner does, and I wish more runners did this: https://github.com/google/tachometer

### [vlovich123](<https://news.ycombinator.com/item?id=49979422>)

> Really depends on what you benchmark and how reliable you want the measurement and what domain you are benchmarking. For example, criterion can sometimes spend quite a bit of time because it needs to stabilize the measurements. The author’s claim is “well you don’t need that accuracy” but I’ve seen wasted time chasing ghosts or making claims on performance improvements that were either neutral or net negative due to this noise.
>
> \> Anything faster than, say, 10ms risks being skewed by fixed costs (e.g, interpreter startup).
>
> Sounds like the author’s experience is strictly in Python. For example with Java you have to make sure the JIT has sufficient optimized your program.
>
> Additionally there’s plenty of situations where it can take a really long time to generate a representative dataset worth benchmarking and it can take time to evaluate the performance (eg databases). Short and quick microbenchmarks can be useful as building points, but at some point you need to evaluate steady state performance of the full thing. Other domains this comes up with is game rendering performance where a 300ms sample tells you nothing about whether you have frame drops after minute 25 or have a memory leak.

### [hinkley](<https://news.ycombinator.com/item?id=49982444>)

> \> human-perceptible range allows me to use my intuitive sense of time and speed
>
> I didn’t intend to specialize in performance early in my career but it happened anyway. I tuned boring homework assignments to make them more interesting for myself. But I moved far away for my first gig out of school and when I showed up the UI painted so slow it looked like one of those videos of an artist drawing something by hand but sped up. I hid my panic at having my name associated with this stinking pile and as soon as I’d done a couple of challenging bug fixes to prove I wasn’t an idiot I got to work.
>
> My first dozen changes needed no benchmarks, In part because I had the slowest machine in the office. I could literally count seconds in my head and tell that I’d taken >1/4 of a second off of an operation because I made it a syllable or two farther in the old version. Later on I used the stopwatch function on a handheld device, to catch 100ms differences. I was there for nearly two months before I needed to put console output of (end - start) into the code for the first time.
>
> By the time I started running out of stuff I knew how to fix, the corpus of data had started showing a serious scalability problem in the data filtering operations, so we were back into classical architectural misdeeds. We had a 2n logn² intersection test that did two scans on different criteria and compared the results using a quadratic time comparison. This code was copy pasta’d in dozens and dozens of places around […]

### [linsomniac](<https://news.ycombinator.com/item?id=49982636>)

> One of the smartest guys I know said: The longer you let a benchmark run, the more certain you can be that it captures other unrelated activity.
>
> His theory was you want to run a benchmark several times, for short periods of time, and take the fastest run as the benchmark.
>
> I ended up doing a lot of benchmarking for the Python Need For Speed Sprint, and that advice seemed to work out well for us there.

### [vardump](<https://news.ycombinator.com/item?id=49979562>)

> Benchmarking like that is often broken because of continuous CPU core clock speed adjustments, system interrupts, SMIs, etc.
>
> I tried to fix it by switching hyperthreading off, playing with the scaling governor, boost, setting a CPU frequency to no avail. The jitter was too much and the results were not reproducible, so I just gave up.
>
> Of course your mileage may vary; this was on an AMD Zen 3 CPU.

---

## Cite

- Page: https://zeli.app/story/49967427
- Date: 2026-10-05
- Source: matklad.github.io (https://matklad.github.io/2026/10/05/benchmark-milliseconds.html)
- Hacker News: https://news.ycombinator.com/item?id=49967427

## Other languages

- zh: https://zeli.app/zh/story/49967427 · markdown: https://zeli.app/zh/story/49967427.md
- ja: https://zeli.app/ja/story/49967427 · markdown: https://zeli.app/ja/story/49967427.md
- ko: https://zeli.app/ko/story/49967427 · markdown: https://zeli.app/ko/story/49967427.md
- de: https://zeli.app/de/story/49967427 · markdown: https://zeli.app/de/story/49967427.md
- es: https://zeli.app/es/story/49967427 · markdown: https://zeli.app/es/story/49967427.md
- ru: https://zeli.app/ru/story/49967427 · markdown: https://zeli.app/ru/story/49967427.md
