time says “it felt fast.” hyperfine says “here is the mean, the noise, and which one actually won.”
hyperfine is a command-line benchmarking tool: give it one or more shell commands, it warms up, runs them enough times to be honest, and prints a statistical summary. Use it when you are about to commit to a “faster” rewrite, compare rg vs grep on your tree, or settle an argument about startup cost. It is not a profiler for internal functions — it is the outer stopwatch done properly, with warmup runs so cold caches do not fake a victory.
install
# macOS
brew install hyperfine
# Debian/Ubuntu
sudo apt install hyperfine
# Fedora
sudo dnf install hyperfine
# Arch
sudo pacman -S hyperfine
examples
# Compare two approaches (warmup discards cold-start noise)
hyperfine --warmup 3 'rg -n TODO .' 'grep -R TODO .'
# Fixed number of runs when you need repeatability
hyperfine --warmup 1 --runs 20 'python3 -c "print(42)"'
# Prepare once, benchmark the hot path
hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null' 'find . -name "*.py"'
# Export markdown table for a PR or notes file
hyperfine --export-markdown /tmp/bench.md 'eza -la' 'ls -la'
cat /tmp/bench.md
# Shell setup that should not count toward timing
hyperfine --shell bash -N 'true' 'sleep 0.01'
pro tip
Benchmark the command you will actually ship, on data that looks like production. Micro-benches on tiny fixtures lie. And always look at the ±σ — a “winner” inside the noise is not a winner.
honest limits
hyperfine times whole processes, not functions inside them — use a real profiler for that. I/O-bound and network-bound work will jitter; pin CPU governors and quiet the machine if you care about single-digit percents. --prepare with drop_caches needs root and is Linux-specific. Do not paste benchmark results from a busy laptop as gospel for a server fleet.