-
Notifications
You must be signed in to change notification settings - Fork 21
/
benchmark_spring_compare.sh
executable file
·157 lines (126 loc) · 2.77 KB
/
benchmark_spring_compare.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
# Syntax: "./benchmark_compare.sh {times} {profile} ({profile})*
#
# This script requires bash 4.0+ and awk
#
iter=$1
shift # eat $1
itermaxlen=`expr length $iter`
timemaxlen=15
profilenamemaxlen=0
commandbase="./benchmark_spring.sh -t "
#
# INITIALIZE VARIABLES
#
declare -A times
declare -A iters
for profile in "$@";
do
iters["$profile"]=0
len=`expr length $profile`
if [ "$profilenamemaxlen" -lt "$len" ];
then
profilenamemaxlen=$len
fi
done
#
# EXECUTE BENCHMARK $iter TIMES FOR EACH $profile
#
for i in `seq 1 $iter`;
do
for profile in "$@";
do
profileiters=${iters["$profile"]}
time_nanos="$($commandbase $profile)"
if [ "$time_nanos" != "0" ];
then
((profileiters+=1))
times["$profile,$profileiters"]=$time_nanos
iters["$profile"]=$profileiters
fi=`printf "%0"$itermaxlen"s" "$i"`
fprofile=`printf "%-"$profilenamemaxlen"s" "$profile"`
ftime=`printf "%"$timemaxlen"sns" "$time_nanos"`
echo "[$fprofile][$fi] $ftime"
fi
done
done
#
# OUTPUT OK/NO OK
#
echo "
----RESULTS--------
"
for profile in "$@";
do
profileiter=${iters["$profile"]}
fprofile=`printf "%-"$profilenamemaxlen"s" "$profile"`
if [ $profileiter == $iter ];
then
echo "[$fprofile] ALL OK";
else
echo "[$fprofile] WITH ERRORS";
fi
done
#
# SUM UP TIMES FOR EACH PROFILE
#
declare -A sumtimes
for profile in "$@";
do
profilesum=0
profiletimes=${times["$profile"]}
timeslen=${iters["$profile"]}
for i in `seq $timeslen`;
do
profileitertime=${times["$profile,$i"]}
((profilesum+=profileitertime))
done
sumtimes["$profile"]=$profilesum
done
#
# COMPUTE AVERAGE TIMES
#
declare -A avgtimes
for profile in "$@";
do
profiletime=${sumtimes["$profile"]}
profileiters=${iters["$profile"]}
profileavg=`awk 'BEGIN{printf("%0.2f", '$profiletime' / '$profileiters')}'`
avgtimes["$profile"]=$profileavg
done
#
# COMPUTE SMALLEST (REFERENCE) VALUE
#
smallestvalue=0.0
smallestprofile=
for profile in "$@";
do
profileavg=${avgtimes["$profile"]}
iszero=$(awk 'BEGIN{ print "'$smallestvalue'" == "0.0" }')
cond=$(awk 'BEGIN{ print "'$profileavg'" < "'$smallestvalue'" }')
if [ "$iszero" == 1 ] || [ "$cond" == 1 ];
then
smallestvalue=$profileavg
smallestprofile=$profile
fi
done
#
# OUTPUT RESULTS
#
echo "
----TOTAL TIMES----
"
for profile in "$@";
do
profileavg=${avgtimes["$profile"]}
profileiters=${iters["$profile"]}
fprofile=`printf "%-"$profilenamemaxlen"s" "$profile"`
ftime=`printf "%"$timemaxlen"sns" "$profileavg"`
if [ "$profile" == "$smallestprofile" ];
then
echo "[$fprofile][$profileiters] $ftime *"
else
difference=`awk 'BEGIN{printf("%0.2f", '$profileavg' / '$smallestvalue' * 100)}'`
echo "[$fprofile][$profileiters] $ftime ($difference%)"
fi
done