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
Provenance
- Commit
32e80fb- Tree
e4d1708- Author
наб <nabijaczleweli@nabijaczleweli.xyz>- Committer
David Peter <mail@david-peter.de>- Parent
779d425
1 file changed+20 added−21 removed
modified:README.md+20 added-21 removed
26 unmodified lines27 ### Basic benchmarks28 29 To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be any30 shell command. For example:31-``` bash31+```sh32 hyperfine 'sleep 0.3'33 ```34 35 Hyperfine will automatically determine the number of runs to perform for each command. By default,36 it will perform *at least* 10 benchmarking runs and measure for at least 3 seconds. To change this,37 you can use the `-r`/`--runs` option:38-``` bash38+```sh39 hyperfine --runs 5 'sleep 0.3'40 ```41 42 If you want to compare the runtimes of different programs, you can pass multiple commands:43-``` bash43+```sh44 hyperfine 'hexdump file' 'xxd file'45 ```46 47 ### Warmup runs and preparation commands2 unmodified lines50 by disk caches and whether they are cold or warm.51 52 If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to53 perform a certain number of program executions before the actual benchmark:54-``` bash54+```sh55 hyperfine --warmup 3 'grep -R TODO *'56 ```57 58 Conversely, if you want to run the benchmark for a cold cache, you can use the `-p`/`--prepare`59 option to run a special command before *each* timing run. For example, to clear harddisk caches60 on Linux, you can run61-``` bash61+```sh62 sync; echo 3 | sudo tee /proc/sys/vm/drop_caches63 ```64 To use this specific command with hyperfine, call `sudo -v` to temporarily gain sudo permissions65 and then call:66-``` bash66+```sh67 hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'68 ```69 70 ### Parameterized benchmarks71 72 If you want to run a series of benchmarks where a single parameter is varied (say, the number of73 threads), you can use the `-P`/`--parameter-scan` option and call:74-``` bash74+```sh75 hyperfine --prepare 'make clean' --parameter-scan num_threads 1 12 'make -j {num_threads}'76 ```77 This also works with decimal numbers. The `-D`/`--parameter-step-size` option can be used78 to control the step size:79-``` bash79+```sh80 hyperfine --parameter-scan delay 0.3 0.7 -D 0.2 'sleep {delay}'81 ```82 This runs `sleep 0.3`, `sleep 0.5` and `sleep 0.7`.83 6 unmodified lines90 ### Intermediate shell91 92 By default, commands are executed using a predefined shell (`/bin/sh` on Unix, `cmd.exe` on Windows).93 If you want to use a different shell, you can use the `-S, --shell <SHELL>` option:94-``` bash94+```sh95 hyperfine --shell zsh 'for i in {1..10000}; do echo test; done'96 ```97 98 Note that hyperfine always *corrects for the shell spawning time*. To do this, it performs a calibration10 unmodified lines109 110 111 ### Shell functions and aliases112 113-If you are using bash, you can export shell functions to directly benchmark them with hyperfine:113+Bash supports passing functions through the environment:114 115+```bash116+my_function() { sleep 1; }117+export -f my_function118+hyperfine --shell=bash my_function119 ```116-$ my_function() { sleep 1; }117-$ export -f my_function118-$ hyperfine my_function119-```120 121-If you are using a different shell, or if you want to benchmark shell aliases, you may try to put122-them in a separate file:121+Otherwise, inline them into or source them from the benchmarked program:122 124-```bash125-echo 'my_function() { sleep 1 }' > /tmp/my_function.sh123+```sh124+hyperfine 'my_function() { sleep 1; }; my_function'125+126 echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh127-hyperfine 'source /tmp/my_function.sh; eval my_function'128-hyperfine 'source /tmp/my_alias.sh; eval my_alias'127+hyperfine '. /tmp/my_alias.sh; my_alias'128 ```129 130 ### Exporting results131 132 Hyperfine has multiple options for exporting benchmark results to CSV, JSON, Markdown and other133 formats (see `--help` text for details).134 136-#### Markdown 135+#### Markdown136 137 You can use the `--export-markdown <file>` option to create tables like the following:138 139 | Command | Mean [s] | Min [s] | Max [s] | Relative |155 unmodified lines