Skip to content
Myr

Update documentation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by GitHub · parent 5c676a9 · Browse files · 1 file+42 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+42 added−10 removed

  • other:+42 added−10 removed

1 file+42 added−10 removed

modified:README.md+42 added-10 removed
22 unmodified lines
23* Cross-platform2425## Usage2627### Basic benchmark27### Basic benchmarks2829To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be any30shell command. For example:31``` bash32hyperfine 'sleep 0.3'33```3435Hyperfine will automatically determine the number of runs to perform for each command. By default,36it will perform *at least* 10 benchmarking runs. To change this, you can use the `-m`/`--min-runs`37option:36it will perform *at least* 10 benchmarking runs and measure for at least 3 seconds. To change this,37you can use the `-r`/`--runs` option:38``` bash39hyperfine --min-runs 5 'sleep 0.2' 'sleep 3.2'39hyperfine --runs 5 'sleep 0.3'40```4142If you want to compare the runtimes of different programs, you can pass multiple commands:43``` bash44hyperfine 'hexdump file' 'xxd file'45```4647### Warmup runs and preparation commands4844If the program execution time is limited by disk I/O, the benchmarking results can be heavily45influenced by disk caches and whether they are cold or warm.49For programs that perform a lot of disk I/O, the benchmarking results can be heavily influenced50by disk caches and whether they are cold or warm.5147If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to perform48a certain number of program executions before the actual benchmark:52If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to53perform a certain number of program executions before the actual benchmark:54``` bash55hyperfine --warmup 3 'grep -R TODO *'56```57
2 unmodified lines
60on Linux, you can run61``` bash62sync; echo 3 | sudo tee /proc/sys/vm/drop_caches63```59To use this specific command with Hyperfine, call `sudo -v` to temporarily gain sudo permissions64To use this specific command with hyperfine, call `sudo -v` to temporarily gain sudo permissions65and then call:66``` bash67hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'68```6970### Parameterized benchmarks7167If you want to run a benchmark where only a single parameter is varied (say, the number of72If you want to run a series of benchmarks where a single parameter is varied (say, the number of73threads), you can use the `-P`/`--parameter-scan` option and call:74``` bash75hyperfine --prepare 'make clean' --parameter-scan num_threads 1 12 'make -j {num_threads}'76```
3 unmodified lines
80hyperfine --parameter-scan delay 0.3 0.7 -D 0.2 'sleep {delay}'81```82This runs `sleep 0.3`, `sleep 0.5` and `sleep 0.7`.8384For non-numeric parameters, you can also supply a list of values with the `-L`/`--parameter-list`85option:86```87hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'88```8990### Intermediate shell9192By default, commands are executed using a predefined shell (`/bin/sh` on Unix, `cmd.exe` on Windows).93If you want to use a different shell, you can use the `-S, --shell <SHELL>` option:94``` bash95hyperfine --shell zsh 'for i in {1..10000}; do echo test; done'96```9798Note that hyperfine always *corrects for the shell spawning time*. To do this, it performs a calibration99procedure where it runs the shell with an empty command (multiple times), to measure the startup time100of the shell. It will then subtract this time from the total to show the actual time used by the command101in question.102103If you want to run a benchmark *without an intermediate shell*, you can use the `-N` or `--shell=none`104option. This is helpful for very fast commands (< 5 ms) where the shell startup overhead correction would105produce a significant amount of noise. Note that you can not use shell syntax like `*` or `~` in this case.106```107hyperfine -N 'grep TODO /home/user'108```109110111### Shell functions and aliases112113If you are using bash, you can export shell functions to directly benchmark them with hyperfine:114
157 unmodified lines