Created
September 26, 2017 13:22
-
-
Save edvardm/979712deedbbb7d23a88637727220b52 to your computer and use it in GitHub Desktop.
Script to run command multiple times and return averages
This file contains hidden or 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 | |
# Script originally by bobmcn, taken from | |
# https://stackoverflow.com/questions/17601539/calculate-the-average-of-several-time-commands-in-linux | |
# Changelog: added NSAMPLES to run given script only given number of times (defaults to 3) | |
NSAMPLES=${NSAMPLES-3} | |
rm -f /tmp/mtime.$$ | |
for x in `seq 1 $NSAMPLES` | |
do | |
/usr/local/bin/gtime -f "real %e user %U sys %S" -a -o /tmp/mtime.$$ $@ | |
tail -1 /tmp/mtime.$$ | |
done | |
echo '---------------------------------------------' | |
awk '{ et += $2; ut += $4; st += $6; count++ } END { printf "Average:\nreal %.3f user %.3f sys %.3f\n", et/count, ut/count, st/count }' /tmp/mtime.$$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment