-
Notifications
You must be signed in to change notification settings - Fork 11
/
benchmark.sh
executable file
·60 lines (47 loc) · 1.03 KB
/
benchmark.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
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# 2016, Georg Sauthoff <[email protected]>
set -eu
time=/usr/bin/time
Rscript=Rscript
f=$(mktemp)
function cleanup
{
rm -f "$f"
}
trap cleanup EXIT
if [ "$1" = -h -o "$1" = --help ]; then
cat <<EOF
Usage: $0 REPEATS COMMAND ARGS..
$0 [OPTIONS] REPEATS COMMAND ARGS..
Options:
-s SECONDS seconds to sleep after each iteration
EOF
fi
s=0
if [ "$1" = -s ]; then
shift
s=$1
shift
fi
n=$1
shift
echo wall,user,sys,rss > "$f"
for i in $(seq $n); do
"$time" --output "$f" --append --format '%e,%U,%S,%M' "$@" >/dev/null
if [ "$s" -gt 0 ]; then
sleep "$s"
fi
done
{
echo "n="$n" min Q1 med mean Q3 max std"
"$Rscript" --vanilla -e \
"b=read.csv(file='$f'); summary(b); options(digits=3); sapply(b, sd);" \
| sed 's/ [^:]\+:/ /g' \
| grep -v 'a' \
| tr ' ' '\n' \
| grep '[0-9]' \
| awk 'BEGIN { b[0]="wall"; b[1]="user"; b[2]="sys"; b[3]="rss" }
{ a[(NR-1)%4] = a[(NR-1)%4]$0" " }
END {for (i=0; i<4; ++i)
print(b[i]" "a[i]) } '
} | column -t -o ' | '