-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstopwatch
More file actions
executable file
·49 lines (44 loc) · 1.81 KB
/
stopwatch
File metadata and controls
executable file
·49 lines (44 loc) · 1.81 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
#!/bin/bash
# Usage: stopwatch tests.file > output.file
#
# Measures the execution time (in seconds) of every possible combination of
# arguments in the testset file and echoes the results in columnated format
# to standard output. Total execution time is echoed to standard error.
# The leftmost column is blank if the process in question completed without
# issue and contains a '!' if it exited with a non-zero status.
#
# The testset file must contain one parameter per line, with no spaces
# within parameters. A line starting with ::: marks the start of a new
# parameter dimension. If you need column headers in the output, you can
# follow the :::'s with whitespace and the dimension name. (The astute reader
# may have observed that this file looks suspiciously like an argument list to
# GNU parallel, and that is exactly how it is used.) Lines may be commented
# by prefixing them with a #.
#
# Example: stopwatch testset 1> results.csv 2> totaltime
dimensions=$(grep -c ^::: "$1")
headers=($(grep ^::: "$1"| cut -c 5-))
format="%c"
for lineno in $(grep -n ^::: "$1" | grep -oP '\d+'); do
maxlen=0
for word in $(sed -n "$lineno,/^:::/p" "$1" | head -n-1 | grep -v '^#'); do
if [ ${#word} -gt $maxlen ] ; then
maxlen=${#word}
fi
done
format="$format %-${maxlen}s"
done
format="$format %7s %7s\n"
if [ ${#headers[@]} -eq $dimensions ] ; then
headerflag='--header :'
printf "$format" '?' "${headers[@]}" real user
args=$(for x in "${headers[@]}"; do echo -n "{$x} "; done)
else
args=$(seq -s ' ' -f '{%0.0f}' $dimensions)
fi
time parallel --max-procs 1 $headerflag "
TIMEFORMAT='%3E %3U'
result=\$((time $args 1>/dev/null 2>/dev/null) 2>&1)
[ \$? -eq 0 ] && status=' ' || status='!'
printf '$format' \"\$status\" $args \$result
" $(grep -v '^#' "$1")