Skip to content

Instantly share code, notes, and snippets.

@mfurquimdev
Created August 2, 2014 04:03
Show Gist options
  • Save mfurquimdev/5abbb4d52699a7a30ece to your computer and use it in GitHub Desktop.
Save mfurquimdev/5abbb4d52699a7a30ece to your computer and use it in GitHub Desktop.
Run a program several times and measure the average time spent to run the program in microseconds
#!/bin/bash
sum=0;
for (( i = 0; i < 10; i++ )); do
begin=`date +%s%N`
#####################################################
#############The Program Should Run Here#############
#####################################################
end=`date +%s%N`
time_spent=$((end - begin))
sum=$((sum + time_spent))
echo "Begin: $(($begin/1000)).$(($begin%1000))"
echo "End: $(($end/1000)).$(($end%1000))"
echo "Time: $(($time_spent/1000)).$(($time_spent%1000))"
echo "Avg: $(($sum/$((1000*(($i+1)))))).$(((($sum%1000))*(($i+1))))"
echo "Sum: $(($sum/1000)).$(($sum%1000))"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment