
Hyperfine: How to Ignore Failed Commands
Updated
Learn how to ignore failed commands when benchmarking with hyperfine

Before we start, make sure you have hyperfine installed on your computer. If you don't have it yet, run this command:
brew install hyperfine
By default, hyperfine stops as soon as a command exits with a non-zero status code. For example, grep exits with 1 when it finds no match, so this benchmark fails straight away:
hyperfine 'grep -q banana notes.txt'
To keep going, add the -i flag, short for --ignore-failure, before your command:
hyperfine -i 'grep -q banana notes.txt'
Hyperfine now runs the command as many times as it needs and prints the usual results, plus a small warning that it ignored the non-zero exit code.
If you only want to ignore the exit codes you expect, pass them after an equals sign. Just remember to replace 1 with the code your command returns:
hyperfine --ignore-failure=1 'grep -q banana notes.txt'
One more tip: failed runs are still timed, so a command that crashes straight away will make your average look faster than it really is. If a command is failing and you don't know why, run it with --show-output first to see everything it prints.
