-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatime
More file actions
executable file
·67 lines (59 loc) · 1.57 KB
/
atime
File metadata and controls
executable file
·67 lines (59 loc) · 1.57 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
65
66
67
# Return $command average run time
#!/bin/bash
set -euo pipefail
# Check if GNU time is installed
if ! command -v time >/dev/null 2>&1 ; then
echo "GNU time is required, please install it" 1>&2
exit 1
fi
function usage {
printf "Usage: %s [OPTIONS] COMMAND\n" "$(basename $0)" 1>&2
printf "Return COMMAND average run time.\n"
printf "\tOptions:\n"
printf "\t-n NUM\t\tRun given command N times (max 100)\n"
exit 2
}
function check_args {
optstring=":hn:"
while getopts ${optstring} arg; do
case "${arg}" in
h)
usage
;;
n)
if [[ ${OPTARG} < 0 || ${OPTARG} > 100 ]]; then
echo "$0: arguments $OPTARG accepts an integer between 1 and 100" >&2
exit 3
fi
REPS="${OPTARG}"
;;
:)
echo "$0: Must supply an argument to -$OPTARG." >&2
exit 4
;;
?)
echo "Invalid option: -${OPTARG}." >&2
exit 5
;;
*)
echo "Unknown error occurred" >&2
exit 6
;;
esac
done
}
# Check if 0 arguments were given
if [[ ${#} -eq 0 ]]; then
usage
fi
# Check command-line arguments
check_args "$@"
# Default repetitions
REPS=20
TOT=0
for i in $(seq 1 $REPS); do
TIME=$( (/usr/bin/TIME -f %e $1 > /dev/null) 2>&1 )
TOT=$(echo $TIME + $TOT | bc -l)
done
TOT=$(echo "scale=4; $tottime / $REPS" | bc -l)
printf "Average: %s seconds\n" "$TOT"