Hyperfine: How to Run Multiple Parameters

Updated

Learn how to run multiple parameters in one benchmark with hyperfine

Hyperfine: How to Run Multiple Parameters

Before we start, make sure you have hyperfine installed on your computer and the file you want to benchmark ready in a folder. If you don't have hyperfine yet, run this command:

brew install hyperfine

To benchmark several variations at once, use the -L flag. It takes a name and a comma-separated list of values, and you use that name in curly braces inside your command. Repeat -L for each list:

hyperfine -L cc gcc,clang -L opt O0,O2 '{cc} -{opt} word_count.c -o words'

Just remember to replace word_count.c with your own file. Hyperfine runs every combination, so this gives you four benchmarks: gcc and clang, each at O0 and O2. Every benchmark is labelled with the exact command it ran, and the whole thing takes a few seconds.

For a range of numbers, use the -P flag with a name, a minimum and a maximum:

hyperfine -P n 1 3 'sleep 0.{n}'

That runs sleep 0.1, sleep 0.2 and sleep 0.3. Add the -D flag if you want to change the step size.

undefined

One thing to keep in mind: if you pass more than one command together with a parameter list, hyperfine runs every command for every value, even if a command doesn't use that name. If you want separate variants, skip the list and pass each full command in its own quotes.