This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.sh
105 lines (81 loc) · 2.14 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
function usage {
echo "Usage: $0 <name-of-the-benchmark> <program-name> [-r num]"
echo
echo "This script allowes to create statistics for a given program."
echo "Generated files are:"
echo " - <name-of-the-benchmark>.csv which contains the runtime-data"
echo " - <name-of-the-benchmark>.info which contains additional information about the system that is used for the benchmark."
echo
echo "Parameters:"
echo " -r num"
echo " Specify the amount of repetitions, that are done for each test."
echo " Default: 35"
}
REPETITIONS=35
OUTPUT=""
PROG=""
# read parameters
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-r)
REPETITIONS="$2"
shift # past argument
;;
-h|--help)
usage
exit 0
;;
*)
if [ "$OUTPUT" == "" ]; then
OUTPUT=$key
elif [ "$PROG" == "" ]; then
PROG=$key
else
echo "Unknown parameter: $key"
echo
echo "Use $0 --help for further information!"
exit 1
fi
;;
esac
shift # past argument or value
done
if [ "$OUTPUT" == "" ] || [ "$PROG" == "" ]; then
echo "No output name specified!"
echo
usage
exit 1
fi
# gather computer info
compinfo=$(lscpu)
compinfo_cpucount=$(echo "$compinfo" | grep 'CPU(s):' | cut -c9-)
compinfo_name=$(hostname)
printf "$compinfo_name\n\n" > $OUTPUT.txt
# lscpu >> $OUTPUT.txt
printf "\n\n" >> $OUTPUT.txt
printf "Command: $PROG\n" >> $OUTPUT.txt
printf "Repetitions: $REPETITIONS\n\n" >> $OUTPUT.txt
benchinfo_starttime=$(date '+%F %H:%M:%S')
echo "Starting the benchmark at:" $benchinfo_starttime
echo "Benchmark started:" $benchinfo_starttime >> $OUTPUT.txt
printf "Run;Seconds;Nanoseconds\n" > $OUTPUT.csv
for i in $(seq $REPETITIONS)
do
runoutput=$($PROG)
# echo "$runoutput" >> $OUTPUT.txt
timeline=$(echo "$runoutput" | grep "Time:")
echo $timeline
regex=".* ([0-9]+)s ([0-9]+)ns$"
if [[ $timeline =~ $regex ]]; then
sec="${BASH_REMATCH[1]}"
nsec="${BASH_REMATCH[2]}"
printf "%s;%s;%s;\n" "$i" "$sec" "$nsec" >> $OUTPUT.csv
else
echo "Program gave the wrong output!"
fi
done;
benchinfo_endtime=$(date '+%F %H:%M:%S')
echo "Finished the benchmark at:" $benchinfo_endtime
echo "Benchmark ended:" $benchinfo_endtime >> $OUTPUT.txt