Measure the performance of your code or tools with Hyperfine

We live in a world where we are constantly encouraged to perform better. We need to do more, faster, and better all the time. It’s exhausting. And above all, very stupid.

Besides, we don’t ask that much of our tools. We develop or use them without really thinking about their actual performance. And that’s a shame because as a developer, you might want to measure the execution time of a shell script to see if it’s faster than a previous version. Or be able to compare the speed of execution of different programs to select the best one!

Don’t worry; I’ve got you covered. It’s called Hyperfine, and it’s a command-line benchmarking tool that allows you to compare the execution times of different programs.

This is very useful for measuring, for example, the performance of programs that perform a lot of writes and reads on a disk to see how they behave with or without a cache, or on a hard drive or SSD.

Hyperfine has many features to help you get accurate and reliable results, including statistical analysis across multiple runs, support for arbitrary shell commands, and constant feedback on benchmark progress and ongoing estimates.

To use it, you can, for example, benchmark any command like this:


To test the command, for example, we will do like this: sleep

hyperfine 'sleep 0.3'

So, by default, Hyperfine will perform at least 10 runs of the program and take its measurement each time for 3 seconds for at least 3 seconds. Note that you can change this test duration by using the -r or --runs option and specifying the duration behind.

See also  Recoll: Unleashing the Power of Advanced Software for Efficient Document Retrieval
Screenshot of the Hyperfine interface showing performance measurement results

If you want to compare the execution times of different programs, you can also pass multiple commands to Hyperfine. So to compare the execution times of hexdump and xxd, you can call hyperfine like this:

hyperfine 'hexdump YOUR_FILE' 'xxd YOUR_FILE'

For example, if you have any doubts about the performance of a new version of a tool, Hyperfine can help you compare it with a previous version.

Hyperfine also allows you to run benchmarks where only one parameter changes with each run. It allows you to measure the behavior of a program according to the parameters you make it digest.

In terms of exports, it’s great since you can then retrieve the results in CSV, JSON, Markdown format, etc., to then analyze all this in peace.

In short, it’s a small command-line tool that doesn’t look like much but will be of great help to you to do your benchmarks and compare the execution time of your own codes or third-party tools.

Have a good time!

5/5 - (1 vote)

Mohamed SAKHRI

I am Mohamed SAKHRI, the creator and editor-in-chief of Tech To Geek, where I've demonstrated my passion for technology through extensive blogging. My expertise spans various operating systems, including Windows, Linux, macOS, and Android, with a focus on providing practical and valuable guides. Additionally, I delve into WordPress-related subjects. You can find more about me on my Linkedin!, Twitter!, Reddit

Leave a Comment