-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.sh
executable file
·200 lines (176 loc) · 6.36 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#! /bin/bash
if [ $# -lt 1 ]; then
ROUNDS=10
elif ! [ "$1" -eq "$1" ] 2>/dev/null; then
echo "Please specify the number of execution rounds in the first argument."
exit
else
ROUNDS=$1
fi
RESULTS_FILE=benchmark.csv
BUILD_SCRIPT='build.sh'
LOOPS_DIR='list-processing-loops'
LOOPS_TARGET_DIR="$LOOPS_DIR/target"
LOOPS_NAME='list-processing-benchmark-loops'
LOOPS_JAR="$LOOPS_TARGET_DIR/$LOOPS_NAME.jar"
LOOPS_NATIVE="$LOOPS_TARGET_DIR/$LOOPS_NAME-native"
STREAMS_DIR='list-processing-streams'
STREAMS_TARGET_DIR="$STREAMS_DIR/target"
STREAMS_NAME='list-processing-benchmark-streams'
STREAMS_JAR="$STREAMS_TARGET_DIR/$STREAMS_NAME.jar"
STREAMS_NATIVE="$STREAMS_TARGET_DIR/$STREAMS_NAME-native"
NO_PROCESSING_DIR='no-processing'
NO_PROCESSING_TARGET_DIR="$NO_PROCESSING_DIR/target"
NO_PROCESSING_NAME='no-processing'
NO_PROCESSING_JAR="$NO_PROCESSING_TARGET_DIR/$NO_PROCESSING_NAME.jar"
NO_PROCESSING_NATIVE="$NO_PROCESSING_TARGET_DIR/$NO_PROCESSING_NAME-native"
#
# Returns 0 if provided file is present and 1 if not
#
is_file_present() {
test -f "$1"
}
ensure_presence_of_loops() {
if ! is_file_present $LOOPS_JAR || ! is_file_present $LOOPS_NATIVE; then
(cd $LOOPS_DIR || exit; ./$BUILD_SCRIPT)
fi
}
ensure_presence_of_streams() {
if ! is_file_present $STREAMS_JAR || ! is_file_present $STREAMS_NATIVE; then
(cd $STREAMS_DIR || exit; ./$BUILD_SCRIPT)
fi
}
ensure_presence_of_no_processing() {
if ! is_file_present $NO_PROCESSING_JAR || ! is_file_present $NO_PROCESSING_NATIVE; then
(cd $NO_PROCESSING_DIR || exit; ./$BUILD_SCRIPT)
fi
}
get_col_headings() {
local _T_HEADINGS
for ((i = 1; i <= ROUNDS; i++)); do
_T_HEADINGS+=",T$i"
done
local _OTHER_HEADINGS='Processing,Mode,Description'
echo $_OTHER_HEADINGS$_T_HEADINGS
}
ensure_presence_of_empty_results_file() {
if is_file_present $RESULTS_FILE; then
rm $RESULTS_FILE
fi
touch $RESULTS_FILE
get_col_headings >>$RESULTS_FILE
}
prepare_environment() {
ensure_presence_of_loops
ensure_presence_of_streams
ensure_presence_of_no_processing
ensure_presence_of_empty_results_file
}
#
# Executes given jar and prints execution duration
#
measure_jar_execution() {
local _JAR=$1
START=$(date +%s%N)
java -jar "$_JAR" >/dev/null
END=$(date +%s%N)
echo $((END - START))
}
#
# Executes given binary and prints execution duration
#
measure_native_execution() {
local _NATIVE=$1
START=$(date +%s%N)
"./$_NATIVE" >/dev/null
END=$(date +%s%N)
echo $((END - START))
}
run_loops_jar_benchmark() {
echo "Start benchmark of $ROUNDS executions of list processing through loops in JVM mode"
declare -a LOOPS_JAR_TIMINGS
for ((i = 0; i < ROUNDS; i++)); do
DURATION=$(measure_jar_execution $LOOPS_JAR)
LOOPS_JAR_TIMINGS+=("$DURATION")
done
local JOINED_TIMINGS
JOINED_TIMINGS=$(echo "${LOOPS_JAR_TIMINGS[@]}" | tr ' ' ',')
echo "Loops,JVM,Durations of list processing in JVM mode through loops in nanoseconds,$JOINED_TIMINGS" >>$RESULTS_FILE
echo "Results added to $RESULTS_FILE"
}
run_loops_native_benchmark() {
echo "Start benchmark of $ROUNDS executions of list processing through loops in native mode"
declare -a LOOPS_NATIVE_TIMINGS
for ((i = 0; i < ROUNDS; i++)); do
DURATION=$(measure_native_execution $LOOPS_NATIVE)
LOOPS_NATIVE_TIMINGS+=("$DURATION")
done
local JOINED_TIMINGS
JOINED_TIMINGS=$(echo "${LOOPS_NATIVE_TIMINGS[@]}" | tr ' ' ',')
echo "Loops,Native,Durations of list processing in native mode through loops in nanoseconds,$JOINED_TIMINGS" >>$RESULTS_FILE
echo "Results added to $RESULTS_FILE"
}
run_stream_jar_benchmark() {
echo "Start benchmark of $ROUNDS executions of list processing through streams in JVM mode"
declare -a STREAMS_JAR_TIMINGS
for ((i = 0; i < ROUNDS; i++)); do
DURATION=$(measure_jar_execution $STREAMS_JAR)
STREAMS_JAR_TIMINGS+=("$DURATION")
done
local JOINED_TIMINGS
JOINED_TIMINGS=$(echo "${STREAMS_JAR_TIMINGS[@]}" | tr ' ' ',')
echo "Streams,JVM,Durations of list processing in JVM mode through streams in nanoseconds,$JOINED_TIMINGS" >>$RESULTS_FILE
echo "Results added to $RESULTS_FILE"
}
run_streams_native_benchmark() {
echo "Start benchmark of $ROUNDS executions of list processing through streams in native mode"
declare -a STREAMS_NATIVE_TIMINGS
for ((i = 0; i < ROUNDS; i++)); do
DURATION=$(measure_native_execution $STREAMS_NATIVE)
STREAMS_NATIVE_TIMINGS+=("$DURATION")
done
local JOINED_TIMINGS
JOINED_TIMINGS=$(echo "${STREAMS_NATIVE_TIMINGS[@]}" | tr ' ' ',')
echo "Streams,Native,Durations of list processing in native mode through streams in nanoseconds,$JOINED_TIMINGS" >>$RESULTS_FILE
echo "Results added to $RESULTS_FILE"
}
run_no_processing_jar_benchmark() {
echo "Start benchmark of $ROUNDS executions without processing in JVM mode"
declare -a NO_PROCESSING_JAR_TIMINGS
for ((i = 0; i < ROUNDS; i++)); do
DURATION=$(measure_jar_execution $NO_PROCESSING_JAR)
NO_PROCESSING_JAR_TIMINGS+=("$DURATION")
done
local JOINED_TIMINGS
JOINED_TIMINGS=$(echo "${NO_PROCESSING_JAR_TIMINGS[@]}" | tr ' ' ',')
echo "No processing,JVM,Durations without processing in JVM mode in nanoseconds,$JOINED_TIMINGS" >>$RESULTS_FILE
echo "Results added to $RESULTS_FILE"
}
run_no_processing_native_benchmark() {
echo "Start benchmark of $ROUNDS executions without processing in native mode"
declare -a NO_PROCESSING_NATIVE_TIMINGS
for ((i = 0; i < ROUNDS; i++)); do
DURATION=$(measure_native_execution $NO_PROCESSING_NATIVE)
NO_PROCESSING_NATIVE_TIMINGS+=("$DURATION")
done
local JOINED_TIMINGS
JOINED_TIMINGS=$(echo "${NO_PROCESSING_NATIVE_TIMINGS[@]}" | tr ' ' ',')
echo "No processing,Native,Durations without processing in native mode in nanoseconds,$JOINED_TIMINGS" >>$RESULTS_FILE
echo "Results added to $RESULTS_FILE"
}
START_WHOLE=$(date +%s%N)
prepare_environment
START_BENCHMARK=$(date +%s%N)
run_loops_jar_benchmark
run_loops_native_benchmark
run_stream_jar_benchmark
run_streams_native_benchmark
run_no_processing_jar_benchmark
run_no_processing_native_benchmark
END_WHOLE=$(date +%s%N)
DURATION_WHOLE_NS=$((END_WHOLE - START_WHOLE))
DURATION_WHOLE_S=$((DURATION_WHOLE_NS/1000000000))
DURATION_BENCHMARK_NS=$((END_WHOLE - START_BENCHMARK))
DURATION_BENCHMARK_S=$((DURATION_BENCHMARK_NS/1000000000))
echo "The whole benchmarking process (incl. builds) lasted $DURATION_WHOLE_S seconds"
echo "The execution of the benchmarked applications lasted $DURATION_BENCHMARK_S seconds"