How to Install and Use hyperfine in Linux for Accurate Command-Line Benchmarking

When optimising shell scripts, evaluating compiler flags, comparing text processing utilities, or contrasting database queries, developers frequently rely on the standard UNIX time command. However, basic execution timing is notoriously susceptible to environmental noise, such as filesystem disk cache differences, CPU frequency scaling governor shifts, and thermal throttling. For reliable performance engineering, you need a benchmark tool that applies rigorous statistical controls.

hyperfine is a modern, Rust-built command-line benchmarking tool designed specifically to measure process execution times with scientific accuracy. Featuring automatic warmup runs, statistical outlier detection, cache clearance hooks, multi-command comparisons, and rich export formats, hyperfine provides crystal-clear performance insights. Here is how to install and master hyperfine on Linux.

Key Advantages of hyperfine Over the time Command

hyperfine elevates benchmarking from crude estimates to reproducible telemetry:

  • Statistical Rigour: Computes mean execution times, standard deviations, minimum/maximum runs, and median values across multiple statistical iterations.
  • Warmup Cycles: Executes specified warmup runs before collecting measurements to ensure files are cached or memory is pre-allocated consistently.
  • Side-by-Side Comparisons: Evaluates multiple competing commands simultaneously and calculates relative speedup ratios (e.g., “Command A is 3.42 times faster than Command B”).
  • Parameterized Benchmarks: Runs sweeps across numerical ranges or variable inputs to test how utilities scale with workload size.

Installing hyperfine on Linux Distributions

hyperfine is available across standard package repositories and standalone binaries.

Method 1: Ubuntu and Debian

On modern Ubuntu (22.04 LTS and newer) and Debian:

sudo apt update
sudo apt install hyperfine -y
hyperfine --version

Method 2: Arch Linux and Fedora

On Arch Linux:

sudo pacman -S hyperfine

On Fedora Linux:

sudo dnf install hyperfine -y

Method 3: Universal Pre-Compiled Binary

To acquire the latest static release directly from GitHub:

curl -LO https://github.com/sharkdp/hyperfine/releases/latest/download/hyperfine-v1.18.0-x86_64-unknown-linux-musl.tar.gz
tar -xvf hyperfine-v1.18.0-x86_64-unknown-linux-musl.tar.gz
sudo install hyperfine-v1.18.0-x86_64-unknown-linux-musl/hyperfine /usr/local/bin/
rm -rf hyperfine-v1.18.0*

Running Your First Benchmark

To benchmark a single command, simply pass the executable string to hyperfine:

hyperfine 'grep -r "TODO" ./src'

hyperfine automatically conducts test runs, estimates duration, performs a minimum of 10 benchmark cycles, and prints a formatted summary complete with mean runtime and standard deviation.

Comparing Competing Tools Side by Side

One of hyperfine’s most popular use cases is contrasting modern CLI tools against legacy counterparts:

hyperfine --warmup 3 'find . -name "*.rs"' 'fd -e rs'

The --warmup 3 flag executes each search three times to populate filesystem caches before actual metrics are logged. The output concludes with a definitive comparison statement:

Summary
  fd -e rs ran
    4.12 ± 0.35 times faster than find . -name "*.rs"
Flag Parameter Purpose
--warmup Number of runs (e.g., -w 3) Warms up disk caches and CPU frequency scaling
--runs Exact run count (e.g., -m 50) Enforces high sample counts for micro-benchmarks
--prepare Command string (e.g., sync; echo 3 > ...) Clears caches or resets database state before each run
--export-markdown File path (e.g., results.md) Generates GitHub-ready Markdown tables for reports

Clearing Caches Between Runs for Cold Benchmarks

If you want to measure true cold disk-read performance, use the --prepare flag to synchronise disks and flush the Linux kernel pagecache before every individual iteration:

hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'du -sh ./large_directory'

Exporting Benchmark Results

For automated CI/CD performance regression testing, hyperfine supports exporting structured data directly into JSON, CSV, and Markdown:

hyperfine --export-json benchmark_results.json 'python3 process.py' 'pypy3 process.py'

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.