Last active
February 25, 2016 00:34
-
-
Save catichenor/d1a14bfbbac30c0de309 to your computer and use it in GitHub Desktop.
How to average the performance results of several runs on a particular command in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
numberOfRuns="10" | |
i="0" | |
while [ $i -lt ${numberOfRuns} ] | |
do | |
results[${i}]=`./performanceTest` # Replace ./performanceTest with the command line of the test you want to run. | |
# ^ This assumes that the result of the test will be a number (integer or decimal). | |
echo "Result this run: ${results[${i}]}" | |
i=$[$i+1] | |
done | |
resultTotal="0" | |
for thisResult in "${results[@]}" | |
do | |
resultTotal=`echo "${resultTotal}+${thisResult}" | bc` | |
done | |
average=`echo "scale=4;${resultTotal}/${numberOfRuns}" | bc` # "scale" controls the decimal places used for the division calculation. | |
echo "The average is: ${average}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment