Same work on each, median of five. The numbers separate three costs that the earlier measurements mixed up: the engine itself (go 23 ms flat, sh 177 ms plus 63 per stack, just 204 plus 32, make 792 plus 700), the shell hooks (about 40 ms per computed setting whatever the engine, since Go runs the same sh), and bin/myos loading a directory's hooks once per stack reference rather than once per directory, which doubles the hook cost for a group. Memoising the lazy defaults changes nothing: the cost is the command substitutions inside each tag helper, not repeated lookups.
17 lines
676 B
Bash
Executable File
17 lines
676 B
Bash
Executable File
#!/bin/sh
|
|
# bench.sh LABEL N -- CMD... run CMD N times, print the median wall time in ms
|
|
# Hermetic: docker is the mock of spec/support/bin, config comes from the
|
|
# environment only, HOME points at the fixture catalogue.
|
|
set -u
|
|
label=$1; n=$2; shift 2; [ "$1" = "--" ] && shift
|
|
i=0; times=""
|
|
while [ "$i" -lt "$n" ]; do
|
|
s=$(python3 -c 'import time;print(int(time.time()*1e6))')
|
|
"$@" >/dev/null 2>&1
|
|
e=$(python3 -c 'import time;print(int(time.time()*1e6))')
|
|
times="$times $(( (e - s) / 1000 ))"
|
|
i=$((i + 1))
|
|
done
|
|
median=$(printf '%s\n' $times | sort -n | awk '{a[NR]=$1} END {print a[int((NR+1)/2)]}')
|
|
printf '%-44s %6s ms (runs:%s)\n' "$label" "$median" "$times"
|