-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark
executable file
·85 lines (80 loc) · 1.57 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -e
run()
{
local name
local prog
local test
local cnt
name="$1"
prog="$2"
test="$3"
cnt="$4"
printf "%s\t" "$name"
for ((i=0; i<$cnt; i++)); do
"$prog" "$test/pat" "$test/txt" o.tmp | paste -s -
done |
awk '
{ b += $1; m += $2; r += $3 }
END {
OFS = "\t"
print b/NR, m/NR, r/NR
}
'
}
format()
{
awk '
BEGIN {
KB = 1024
MB = 1024 * 1024
GB = 1024 * 1024 * 1024
}
{
printf "%s\t%.1fms\t%.1fms\t", $1, $2*1000, $3*1000
if ($4 >= GB)
printf("%.1fGB\n", $4/GB)
else if ($4 >= MB)
printf("%.1fMB\n", $4/MB)
else if ($4 >= KB)
printf("%.1fKB\n", $4/KB)
else
printf("%dB\n", $4)
}
'
}
echo Warning: The unit of RSS may be incorrect on some systems, e.g. Linux.
echo Benchmarking...
sep='-------'
cnt=10
for i in test/alice test/rand test/lfail; do
echo; (
printf '%s\n' "$i"
printf "Prog\tBuild\tMatch\tRSS\n"
printf '%s\t%s\t%s\t%s\n' "$sep" "$sep" "$sep" "$sep"
naive="$(run naive "naive/run.tmp" "$i" "$cnt")"
libaca="$(run libaca ./run.tmp "$i" "$cnt")"
printf "%s\n%s\n" "$naive" "$libaca" | format
printf '%s\t%s\t%s\t%s\n' "$sep" "$sep" "$sep" "$sep"
printf "%s\n%s\n" "$naive" "$libaca" |
awk '{
for (i = 1; i <= 4; i++)
a[NR":"i] = 0+$i
}
END {
printf "Improv"
for (i = 2; i < 4; i++)
if (a[2":"i] > 0) {
d = (a[1":"i] - a[2":"i]) / a[2":"i]
printf "\t%.0f%%", d*100
} else
printf "\t-"
if (a[1":"4] > 0) {
d = (a[1":"4] - a[2":"4]) / a[1":"4]
printf "\t%.0f%%", d*100
} else
printf "\t-"
print ""
}'
) | column -ts' '
done