Skip to content
Myr

Adds tip for benchmarking aliases and functions

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

authored by Thiago Arrais · committed by David Peter · parent c05d7f9 · Browse files · 1 file+20 added−0 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−0 removed

  • other:+20 added−0 removed

1 file+20 added−0 removed

modified:README.md+20 added
38 unmodified lines
39``` bash40hyperfine --min-runs 5 'sleep 0.2' 'sleep 3.2'41```4243### Tip: aliases and functions4445Aliases and shell functions can't be benchmarked directly, but you may try to put them in a separate46file and benchmark _that_:4748```bash49echo 'my_function() { sleep 1 }' > /tmp/my_function.sh50echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh51hyperfine 'source /tmp/my_function.sh; eval my_function'52hyperfine 'source /tmp/my_alias.sh; eval my_alias'53```5455If you're using bash, you may also want to `export` functions (can't do that with aliases, though):5657```58$ my_function() { sleep 1; }59$ export -f my_function60$ hyperfine my_function61```6263### Warmup runs and preparation commands6465If the program execution time is limited by disk I/O, the benchmarking results can be heavily66influenced by disk caches and whether they are cold or warm.
168 unmodified lines