-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.sh
62 lines (52 loc) · 1.57 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
#!/bin/bash
# REQUIRES SUDO
# Benchmark runner
repeats=20
output_file='benchmark_results.csv'
command_to_run='echo 1'
run_tests() {
# --------------------------------------------------------------------------
# Benchmark loop
# --------------------------------------------------------------------------
echo 'Benchmarking ' $command_to_run '...';
# Indicate the command we just run in the csv file
echo '======' $command_to_run '======' >> $output_file;
# Run the given command [repeats] times
for (( i = 1; i <= $repeats ; i++ ))
do
# percentage completion
p=$(( $i * 100 / $repeats))
# indicator of progress
l=$(seq -s "+" $i | sed 's/[0-9]//g')
# runs time function for the called script, output in a comma seperated
# format output file specified with -o command and -a specifies append
/usr/bin/time -f "%E,%U,%S" -o ${output_file} -a ${command_to_run} > /dev/null 2>&1
# Clear the HDD cache (I hope?)
# sync && echo 3 > /proc/sys/vm/drop_caches
echo -ne ${l}' ('${p}'%) \r'
done;
echo -ne '\n'
# Convenience seperator for file
echo '--------------------------' >> $output_file
}
# Option parsing
while getopts n:c:o: OPT
do
case "$OPT" in
n)
repeats=$OPTARG
;;
o)
output_file=$OPTARG
;;
c)
command_to_run=$OPTARG
run_tests
;;
\?)
echo 'No arguments supplied'
exit 1
;;
esac
done
shift `expr $OPTIND - 1`