Created
August 2, 2014 04:03
-
-
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
This file contains 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 | |
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