Evaluating the speed of command-line utilities, compile times, or database query scripts using the basic shell time builtin is fraught with statistical errors. A single run is heavily distorted by disk cache cold starts, CPU frequency throttling, and background operating system spikes. hyperfine, created by David Peter (sharkdp), brings statistical rigor to command-line benchmarking by automating warmup executions, computing statistical variance, detecting outliers, and producing publication-grade markdown and JSON comparison tables.
Key Features of hyperfine
- Automatic Warmup Runs: Use
--warmup 3to run commands three times before recording metrics, ensuring CPU caches and page tables are warm. - Disk Cache Clearing: Benchmark true cold-disk performance using
--prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches'between runs. - Parameterized Sweeps: Use
-P threads 1 16to evaluate scaling across multiple CPU core counts in a single command.
hyperfine Command Recipe Matrix
| Use Case | Command Syntax |
|---|---|
| Compare Two Tools | hyperfine 'fd . /usr' 'find /usr' |
| Warmup + Minimum Runs | hyperfine --warmup 5 --min-runs 20 'python script.py' |
| Export to Markdown | hyperfine --export-markdown benchmark.md 'cargo build' |
- macOS:
brew install hyperfine - Ubuntu / Debian:
sudo apt install hyperfine - Rust Cargo:
cargo install hyperfine
Conclusion
hyperfine transforms performance claims from subjective hunches into repeatable, scientifically sound data.
- hyperfine Official GitHub Repository — Documentation, options, and benchmarks.
Discussion & Issues
Comments
Post a Comment