Tools

hyperfine: benchmark command-line tools properly instead of a single time

TL;DR

A single time run is not a benchmark. hyperfine runs many times with warmup, reports mean ± standard deviation, flags outliers, compares commands and exports markdown tables for PRs.

"The new way is faster" is often concluded from a single time run. But one measurement says little: disk caches, a busy CPU and a cold JIT all make results fluctuate. hyperfine is a benchmarking tool for command-line programs: it runs each command many times, supports warmup rounds, computes mean and standard deviation, detects outliers, and compares several commands with clear numbers.

GitHub page of sharkdp/hyperfine
GitHub page of sharkdp/hyperfine (screenshot, November 2026)

GitHub: https://github.com/sharkdp/hyperfine · about 29k stars · Rust · Apache-2.0/MIT

Installation

brew install hyperfine             # macOS
winget install hyperfine           # Windows
sudo apt install hyperfine         # Ubuntu/Debian
cargo install --locked hyperfine   # with Rust

Basic usage

# Measure one command
hyperfine 'npm run build'

# Compare two approaches
hyperfine 'grep -r TODO src' 'rg TODO src'

# Three warmup runs to warm caches
hyperfine --warmup 3 'python script.py' 'pypy script.py'

For each command you get mean ± standard deviation, min/max and the number of runs, followed by a summary like "command A ran x times faster than command B". hyperfine picks the run count automatically (at least 10 runs, targeting roughly 3 seconds in total) and warns when it detects outliers.

Key options

OptionUse whenExample
--warmup NYou want "warm" cache measurements--warmup 3
--prepare CMDSomething must run before EACH measurement (clear caches, reset data)--prepare 'rm -rf dist'
--runs NYou want a fixed run count--runs 20
-L name a,bComparing a list of parameter values-L c gcc,clang '{c} -O2 main.c'
--parameter-scanScanning a numeric parameter--parameter-scan t 1 8 'make -j {t}'
-NVery fast commands; skip shell startup overheadhyperfine -N 'echo hi'
--export-markdownPasting results into PRs and docs--export-markdown bench.md
--export-jsonKeeping data for charts or later comparison--export-json bench.json

Real-world examples

# Cold build (no cache) vs cached build
hyperfine --prepare 'rm -rf node_modules/.cache dist' 'npm run build'

# Find the best thread count for a build
hyperfine --parameter-scan threads 1 8 'make -j {threads}' --export-markdown jobs.md

# Compare two branches: build a binary from each, then measure
hyperfine './bin-main --input data.csv' './bin-feature --input data.csv'

Caveats

  • Close heavy applications while measuring; on laptops, plug in power so the CPU doesn't throttle.
  • Commands with side effects (writing files, calling APIs) need --prepare so each run starts from the same state.
  • It benchmarks whole commands and doesn't replace a profiler. Once you know something is slow, profile to find where.
  • For sub-millisecond commands use -N, because shell startup dominates the result.

How to apply it

  • Dev: Before claiming "faster", run hyperfine and paste the markdown table into the PR. Numbers with standard deviation beat any explanation.
  • Tech Lead: Keep hyperfine benchmarks for key commands (build, test, main CLI) and compare when upgrading tools, switching bundlers or changing runtime versions.
  • PM: When the team proposes switching tools because it's "faster", ask for hyperfine numbers: how many times faster, on what data.

Sources & references

  1. sharkdp/hyperfine — sharkdp (GitHub)