Skip to content

Instantly share code, notes, and snippets.

@popstas
Created February 28, 2016 22:53
Show Gist options
  • Save popstas/496053088ea8c292618e to your computer and use it in GitHub Desktop.
Save popstas/496053088ea8c292618e to your computer and use it in GitHub Desktop.
Measure average script time execution
#!/bin/bash
set -eu
if [ "$#" != 1 ] && [ "$#" != 2 ]; then
echo "Usage:
# run 'command' with 5 cycles
average 'command'
# run 'command' with 3 cycles
average 3 'command'
# run 'command' with 5 cycles, you can also call 'export CYCLES=5' before call 'average'
CYCLES=5 average 'command'"
exit 1
fi
if [ "$#" = 1 ]; then
cycles=${CYCLES:-5}
cmd="$1"
fi
if [ "$#" = 2 ]; then
cycles="$1"
cmd="$2"
fi
# replace " to \"
cmd=$(echo "$cmd" | sed 's/"/\\"/g')
python -m timeit -n 1 -r ${cycles} -s 'import os' "os.system(\"${cmd}\")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment