-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeit
More file actions
executable file
·65 lines (49 loc) · 1.04 KB
/
Copy pathtimeit
File metadata and controls
executable file
·65 lines (49 loc) · 1.04 KB
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
#!/bin/bash
# VERSION: 0.1
usage() {
cat >&2 <<EOM
usage: $(basename "$0") [options] COMMAND
Time repeated execution of COMMAND.
options:
-h Print this help message
-n NUMBER Run NUMBER trials
EOM
}
NUM=1
while getopts hn: OPT; do
case $OPT in
h)
usage
exit 0
;;
n)
NUM="$OPTARG"
;;
\?)
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ $# -lt 1 ]; then
usage
exit 1
fi
logfile="$(mktemp)"
# shellcheck disable=SC2064
trap "rm '$logfile'" EXIT
start="$(date "+%s.%N")"
seq 1 "$NUM" | while read; do
# TODO: verbose option
#echo>&2 -n '.'
/usr/bin/time -o "$logfile" -a --format '%e' "$@"
done
end="$(date "+%s.%N")"
echo>&2 ''
# WTF bash, no floating point numbers
sum="$(echo "scale=10; $end - $start" | bc -q)"
mean="$(echo "scale=10; $sum / $NUM" | bc -q)"
echo>&2 "count: $NUM"
echo>&2 "total: $(printf "%0.3f" "$sum")"
echo>&2 "mean: $(printf "%0.3f" "$mean")"