Skip to content

Instantly share code, notes, and snippets.

@christianbundy
Forked from neale/Program timer
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianbundy/8f5530a2814065b6f665 to your computer and use it in GitHub Desktop.
Save christianbundy/8f5530a2814065b6f665 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
trap 'exit' ERR # exit on error (better than `set -e`)
set -x # echo commands before running
set -u # throw error if an unbound variable is called
BASEDIR=$(cd $(dirname $0) && pwd) # path to directory for itself
LOGDIR="$BASEDIR/times" # directory for logging
LOGFILE="$LOGDIR/times.txt" # file for logging (within $LOGDIR)
# create array from finding files in directory (except itself)
IFS=$'\n'
PROGRAMS=($(find $BASEDIR -maxdepth 1 -type f | grep -v "$(basename $0)"))
# create array from reading string
IFS=' '
read -a ITERATIONS <<< "1 5 10 50 100 500 1000 5000 10000 50000 100000"
mkdir -p $LOGDIR # create directory, but don't fail if it already exists
touch $LOGFILE # create/truncate file
for p in "${PROGRAMS[@]}"; do
for i in "${ITERATIONS[@]}"; do
# append output of each program and iteration combination to $LOGFILE
$p $i >> $LOGFILE
done
done
echo "Finished! Times for each program can be found in $LOGFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment