TL;DR — Quick Summary
Hyperfine runs commands multiple times, performs statistical analysis, and detects outliers. The proper way to benchmark CLI programs — not just 'time' in a loop.
Hyperfine takes the guesswork out of performance testing. Instead of running time once and guessing, Hyperfine runs your command many times, handles cache warm-up, detects statistical outliers, and tells you with confidence which approach is faster.
Installation
# macOS
brew install hyperfine
# Arch Linux
sudo pacman -S hyperfine
# Ubuntu/Debian
sudo apt install hyperfine
# Cargo
cargo install hyperfine
Basic Benchmarking
# Benchmark a single command
hyperfine 'sleep 0.3'
# Output:
# Time (mean ± σ): 300.2 ms ± 0.3 ms
# Range (min … max): 299.8 ms … 300.7 ms
# 10 runs
# With warmup (3 runs before measuring)
hyperfine --warmup 3 'grep -r TODO src/'
# Specify number of runs
hyperfine --runs 50 'echo hello'
Comparing Commands
# Compare fd vs find
hyperfine 'fd -e py' 'find . -name "*.py"'
# Summary: fd is 8.3x faster than find
# Compare grep alternatives
hyperfine 'grep -r TODO .' 'rg TODO' 'ag TODO'
# Compare shell scripts
hyperfine './build-v1.sh' './build-v2.sh' --warmup 2
# With labels
hyperfine -n 'ripgrep' 'rg TODO' -n 'grep' 'grep -r TODO .'
Advanced Features
# Clear disk cache before each run (cold benchmark)
hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -r TODO .'
# Setup command
hyperfine --setup 'make build' 'make test'
# Parameter scan (benchmark with different values)
hyperfine --parameter-scan threads 1 8 'make -j {threads}'
# Export results
hyperfine 'fd -e py' 'find . -name "*.py"' \
--export-json results.json \
--export-markdown results.md \
--export-csv results.csv
Summary
- Hyperfine benchmarks CLI commands with statistical analysis — not just
time - Runs commands multiple times, calculates mean/min/max/standard deviation
- Warm-up runs, cache clearing, and outlier detection built-in
- Compare multiple commands side-by-side with relative performance
- Export to JSON, CSV, and Markdown for reports