Benchmark Your Terminal Commands Like a Scientist
Ever found yourself in a terminal debate about which command is faster? Maybe you're tweaking a script, comparing two tools, or just curious if your new alias actually saves time. Your usual method might be slapping time in front of a command and running it a couple of times. But let's be honest, that's not exactly rigorous. What about caching, system load, or statistical variance? Enter Hyperfine.
It's a command-line benchmarking tool that treats performance testing with the seriousness it deserves. Instead of a single rough guess, it gives you statistically sound results, helping you make confident decisions about performance.
What It Does
Hyperfine is a terminal tool that benchmarks other commands. You give it a command (or several), and it runs them repeatedly, automatically figuring out how many runs are needed to get reliable results. It then spits out a clear summary with average times, standard deviation, and even a comparison if you benchmark multiple commands.
Why It's Cool
The magic of Hyperfine is in its thoughtful, automated approach to a usually manual and error-prone task.
- Statistical Rigor Out of the Box: It performs a warmup run to account for filesystem caching, and it runs enough iterations to provide stable results. You get metrics like mean, standard deviation, and median, so you understand not just the raw speed but the consistency.
- Effortless Comparisons: Benchmark two commands side-by-side with
hyperfine 'npm start' 'pnpm start'. It will run both and present a clear table showing which is faster and by what percentage. No mental math required. - It Handles the Annoying Stuff: It automatically alternates the order of commands to cancel out caching or ordering biases. You can also set a minimum benchmarking time, so it does the heavy lifting of calculating the required number of runs.
- Great Output Options: Get simple tables, detailed Markdown for your READMEs, or even generate beautiful HTML charts with a single
--export-jsonflag followed by a quick script. - It's Just One Binary: Written in Rust, it's a fast, self-contained tool with no runtime dependencies. Download it and run it.
How to Try It
Getting started is straightforward. You can install it via your package manager of choice.
On macOS with Homebrew:
brew install hyperfine
On Linux (many distros):
sudo apt install hyperfine # Debian/Ubuntu
sudo dnf install hyperfine # Fedora
You can also download the pre-built binary for your platform directly from the GitHub releases page.
Once installed, the basic syntax is simple:
hyperfine 'your-command-here'
Try something immediate:
hyperfine 'ls -la' 'exa -la'
Or benchmark a script you're working on:
hyperfine './my-script.sh'
Final Thoughts
Hyperfine is one of those tools that instantly becomes part of my workflow. It replaces a hacky, manual process (for i in {1..5}; do time command; done) with something trustworthy and effortless. It's perfect for optimizing your dotfiles, validating performance claims in a project, or just satisfying your own curiosity about what's happening under the hood. Next time you wonder "which one is faster?", skip the guesswork and let Hyperfine give you a real answer.
@githubprojects
Repository: https://github.com/sharkdp/hyperfine