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 105
|
#!/usr/bin/env bash
# This runs a benchmark while measuring the time taken.
# $1 The Frobby action to run (e.g. alexdual)
# $2 The name of one or more space-separated input files
# $3+ Parameters to Frobby
#
# The time printed is the user CPU time that Frobby took to complete
# the computation.
#
# Parameter 2 can contain more than one file if this script has been called
# as e.g. "../thisscript action "file1 file2"
#
# If $3 is _profile, then the warning Frobby issues on running
# a profile build is not displayed.
#
# If $3 is _runs, then $4 must be an integer, and the benchmark will
# be run that many times
#
# If $3 is _noDetails, then do not display what action is being taken
# on which file, as is otherwise done.
#
# If $3 is _noOFormat, then -oformat null is not applied to
# Frobby. This is useful in case the action does not support oformat.
frobby=../../bin/frobby
TIMEFORMAT="%1Us "
action="$1"
inputFile="$2"
shift
shift
runsToMake=1;
suppresProfile=0;
displayDetails=1;
oformat="-oformat null"
changed=1;
while [ $changed = 1 ];
do
changed=0;
if [ "$1" = "_profile" ];
then
changed=1;
suppressProfile=1;
shift;
fi
if [ "$1" = "_runs" ];
then
changed=1;
runsToMake="$2";
shift;
shift;
fi
if [ "$1" = "_noDetails" ];
then
changed=1;
displayDetails=0;
shift;
fi
if [ "$1" = "_noOFormat" ];
then
changed=1;
oformat="";
shift;
fi
done
params="$*"
function runFrobby {
cat $inputFile|$frobby $action $oformat $params 1>/dev/null 2>&1
}
function suppressFrobby {
if [ "$suppressProfile" = "1" ]; then
runFrobby|sed /PROFILE/d
else
runFrobby
fi
}
function timeFrobby {
# Creating a subshell and using tr is the only way I know of to get
# rid of the trailing newline that time appends to the end. We have
# to get rid of this to put more than one benchmark time on the same
# line.
(time suppressFrobby) 2>&1|tr -d '\012'
}
if [ "$displayDetails" = "1" ]; then
echo -n "$action `basename $inputFile .test`: "
fi
for ((run=0; run<$runsToMake; ++run))
do
timeFrobby
done
echo
|