-
Notifications
You must be signed in to change notification settings - Fork 2
/
bench.sh
executable file
·45 lines (37 loc) · 1020 Bytes
/
bench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
set -euo pipefail
ITERATIONS=103
DELAY="0.02s"
# Number of worst values to not count in the average
THROWAWAY=3
function bench {
cd $1;
results=();
for (( i=0; i<ITERATIONS; i++ ))
do
results+=($($2 | rg "$3" -o -r '$1'))
sleep $DELAY
done
IFS=$'\n' sorted=($(sort -n -r <<<"${results[*]}"))
unset IFS
middle=$(echo "scale=0; $ITERATIONS / 2" | bc -l)
median=${sorted[$middle]}
better=(${sorted[@]:$THROWAWAY})
mean="0"
for r in "${better[@]}"
do
mean=$(echo "$mean + $r" | bc -l)
done
mean=$(echo "scale=5; $mean / ($ITERATIONS - $THROWAWAY)" | bc -l)
rms="0"
for r in "${better[@]}"
do
rms=$(echo "$rms + ($mean - $r)^2" | bc -l)
done
rms=$(echo "scale=5; sqrt($rms / ($ITERATIONS - $THROWAWAY))" | bc -l)
echo "$1: $mean ms (±$rms), median = $median ms"
cd ..;
}
bench blades blades "Done in (.*)ms"
bench zola "zola build" "Done in (.*)ms"
bench hugo hugo "Total in (.*) ms"