hyperfine: Benchmark a Command on the CLI
hyperfine runs a command repeatedly and reports the mean, standard deviation, min, and max wall-clock time, with statistical outlier detection.
hyperfine turns "it feels slower" into a number. It handles warmups, multiple runs, and cache-clearing prep steps so the measurement is honest.
What it does
hyperfine benchmarks one or more shell commands by executing each many times, discarding warmup runs, and computing summary statistics. It auto-determines a run count for short commands, detects outliers, and can compare commands head to head, printing which is faster and by how much.
Common usage
hyperfine 'grep -r foo .' 'rg foo' # compare two commands
hyperfine --warmup 3 './build.sh' # 3 warmup runs first
hyperfine --runs 20 --prepare 'rm -rf out' 'make' # clean before each run
hyperfine -L threads 1,2,4,8 'make -j {threads}' # parameter sweepOptions
| Flag | What it does |
|---|---|
| -w / --warmup <n> | Run the command n times before measuring |
| -r / --runs <n> | Force exactly n measured runs |
| -p / --prepare <cmd> | Run cmd before each timed run (e.g. clear cache) |
| -L / --parameter-list <name> <vals> | Sweep a parameter across values |
| --export-json <file> | Write full results as JSON |
| --export-markdown <file> | Write a Markdown comparison table |
| -N / --shell=none | Skip the intermediate shell for tighter timing |
In CI
Use --warmup so cold caches do not skew the first runs, and --prepare to reset state when each run must start clean. Shared CI runners are noisy neighbors, so expect higher variance than on a laptop; raise --runs and judge by the confidence interval, not a single number.
Common errors in CI
"hyperfine: command not found" (install via cargo install hyperfine, brew install hyperfine, or the GitHub release deb). "Command terminated with non-zero exit code" means your benchmarked command failed; add --ignore-failure only if non-zero is expected, otherwise fix the command. Wildly large stddev usually means a missing --warmup or a noisy runner.