-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark
executable file
·59 lines (45 loc) · 1.1 KB
/
benchmark
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -e
DIR="$(dirname "$0")"
convert_n_times() {
CONVERT_DIR="$1"
FILENAME="$2"
TIMES="$3"
for i in {1..$TIMES}; do
cd "$CONVERT_DIR" && ./convert "$FILENAME" || exit 1
done
}
benchmark_convert() {
CONVERT_DIR="$1"
FILENAME="$2"
TIMES="$3"
time1=$(($(date +%s%N)/1000000))
convert_n_times "$CONVERT_DIR" "$FILENAME" "$TIMES"
time2=$(($(date +%s%N)/1000000))
ms=$((time2 - time1))
average=$((ms / TIMES))
echo >&2 "${FILENAME}: ${ms}ms for ${TIMES} conversions (avg ${average}ms)"
echo $ms
}
benchmark_strategy() {
STRATEGY="$1"
dir="$DIR"/"$STRATEGY"
if [ -x "$dir"/setup ]; then
(cd "$dir" && ./setup)
fi
ms_small=$(benchmark_convert "$dir" small.html 30)
ms_medium=$(benchmark_convert "$dir" medium.html 15)
ms_large=$(benchmark_convert "$dir" large.html 2)
if [ -x "$dir"/teardown ]; then
(cd "$dir" && ./teardown)
fi
total=$((ms_small + ms_medium + ms_large))
echo "$STRATEGY: finished in ${total}ms"
}
if [ -z "$1" ]; then
for strategy in $(echo using-*); do
benchmark_strategy $strategy
done
else
benchmark_strategy $1
fi