Posted By

mattsn0w on 02/16/11


Tagged

time average mean


Versions (?)

calculate mean average from /usr/bin/time results


 / Published in: Bash
 

  1. #!/bin/bash
  2. # calculate the mean average of wall clock time from multiple /usr/bin/time results.
  3. #
  4.  
  5. file=${1}
  6. cnt=0
  7.  
  8. if [ ${#file} -lt 1 ]; then
  9. echo "you must specify a file containing output of /usr/bin/time results"
  10. exit 1
  11. elif [ ${#file} -gt 1 ]; then
  12. samples=(`grep real ${file} | awk '{print $2}' | cut -dm -f2 | cut -ds -f1`)
  13.  
  14. for sample in ${samples}; do
  15. cnt=$(echo ${cnt}+${sample} | bc -l)
  16. done
  17. # Calculate the 'Mean' average (sum / samples).
  18. mean_avg=$(echo ${cnt}/${#samples[@]} | bc -l)
  19. mean_avg=$(echo ${mean_avg} | cut -b0-5)
  20.  
  21. printf "\tSamples:\t%s \n\tMean Avg:\t%s\n\n" ${#samples[@]} ${mean_avg}
  22. fi

Report this snippet  

You need to login to post a comment.