Skip to content

Instantly share code, notes, and snippets.

@jwodder
Created May 11, 2014 21:36
Show Gist options
  • Save jwodder/00550a8cbfec22126bf5 to your computer and use it in GitHub Desktop.
Save jwodder/00550a8cbfec22126bf5 to your computer and use it in GitHub Desktop.
Run a command repeatedly and write the runtimes to a file
#!/bin/bash
n=1000
args=`getopt n:o: $*` || {
echo "Usage: bench [-n runs] [-o outfile] cmd args ..."
exit 2
}
set -- $args
for i
do case "$1" in
-n) n="$2"; shift; shift;;
-o) out="$2"; shift; shift;;
--) shift; break;;
esac
done
TIMEFORMAT=%R
[ -z "$out" ] && out="$1".bench
for ((i=0; i<n; i++))
do #echo $i
( time "$@" > /dev/null ) 2>>$out
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment