From e1fea57182d5ef8ae06fb32c698d2ffa361a7313 Mon Sep 17 00:00:00 2001 From: Thiago Arrais Date: Mon, 19 Oct 2020 13:17:24 -0300 Subject: [PATCH] Adds tip for benchmarking aliases and functions --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 37bce69..6b81e51 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,26 @@ option: hyperfine --min-runs 5 'sleep 0.2' 'sleep 3.2' ``` +### Tip: aliases and functions + +Aliases and shell functions can't be benchmarked directly, but you may try to put them in a separate +file and benchmark _that_: + +```bash +echo 'my_function() { sleep 1 }' > /tmp/my_function.sh +echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh +hyperfine 'source /tmp/my_function.sh; eval my_function' +hyperfine 'source /tmp/my_alias.sh; eval my_alias' +``` + +If you're using bash, you may also want to `export` functions (can't do that with aliases, though): + +``` +$ my_function() { sleep 1; } +$ export -f my_function +$ hyperfine my_function +``` + ### Warmup runs and preparation commands If the program execution time is limited by disk I/O, the benchmarking results can be heavily