Skip to content
Myr

Fix Shell functions and aliases sexion in README

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

And the markdown language tags

authored by наб · committed by David Peter · parent 779d425 · Browse files · 1 file+20 added−21 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+20 added−21 removed

  • other:+20 added−21 removed

1 file+20 added−21 removed

modified:README.md+20 added-21 removed
26 unmodified lines
27### Basic benchmarks2829To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be any30shell command. For example:31``` bash31```sh32hyperfine '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 and measure for at least 3 seconds. To change this,37you can use the `-r`/`--runs` option:38``` bash38```sh39hyperfine --runs 5 'sleep 0.3'40```4142If you want to compare the runtimes of different programs, you can pass multiple commands:43``` bash43```sh44hyperfine 'hexdump file' 'xxd file'45```4647### Warmup runs and preparation commands
2 unmodified lines
50by disk caches and whether they are cold or warm.5152If 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``` bash54```sh55hyperfine --warmup 3 'grep -R TODO *'56```5758Conversely, if you want to run the benchmark for a cold cache, you can use the `-p`/`--prepare`59option to run a special command before *each* timing run. For example, to clear harddisk caches60on Linux, you can run61``` bash61```sh62sync; echo 3 | sudo tee /proc/sys/vm/drop_caches63```64To use this specific command with hyperfine, call `sudo -v` to temporarily gain sudo permissions65and then call:66``` bash66```sh67hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'68```6970### Parameterized benchmarks7172If 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``` bash74```sh75hyperfine --prepare 'make clean' --parameter-scan num_threads 1 12 'make -j {num_threads}'76```77This also works with decimal numbers. The `-D`/`--parameter-step-size` option can be used78to control the step size:79``` bash79```sh80hyperfine --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`.83
6 unmodified lines
90### 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``` bash94```sh95hyperfine --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 calibration
10 unmodified lines
109110111### Shell functions and aliases112113If you are using bash, you can export shell functions to directly benchmark them with hyperfine:113Bash supports passing functions through the environment:114115```bash116my_function() { sleep 1; }117export -f my_function118hyperfine --shell=bash my_function119```116$ my_function() { sleep 1; }117$ export -f my_function118$ hyperfine my_function119```120121If you are using a different shell, or if you want to benchmark shell aliases, you may try to put122them in a separate file:121Otherwise, inline them into or source them from the benchmarked program:122124```bash125echo 'my_function() { sleep 1 }' > /tmp/my_function.sh123```sh124hyperfine 'my_function() { sleep 1; }; my_function'125126echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh127hyperfine 'source /tmp/my_function.sh; eval my_function'128hyperfine 'source /tmp/my_alias.sh; eval my_alias'127hyperfine '. /tmp/my_alias.sh; my_alias'128```129130### Exporting results131132Hyperfine has multiple options for exporting benchmark results to CSV, JSON, Markdown and other133formats (see `--help` text for details).134136#### Markdown 135#### Markdown136137You can use the `--export-markdown <file>` option to create tables like the following:138139| Command | Mean [s] | Min [s] | Max [s] | Relative |
155 unmodified lines