Guest User

Untitled

a guest
Feb 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #!/bin/bash
  2. # Benchmark runner
  3.  
  4. repeats=20
  5. output_file='benchmark_results.csv'
  6. command_to_run='echo 1'
  7.  
  8. run_tests() {
  9. # --------------------------------------------------------------------------
  10. # Benchmark loop
  11. # --------------------------------------------------------------------------
  12. echo 'Benchmarking ' $command_to_run '...';
  13. # Indicate the command we just run in the csv file
  14. echo '======' $command_to_run '======' >> $output_file;
  15.  
  16. # Run the given command [repeats] times
  17. for (( i = 1; i <= $repeats ; i++ ))
  18. do
  19. # percentage completion
  20. p=$(( $i * 100 / $repeats))
  21. # indicator of progress
  22. l=$(seq -s "+" $i | sed 's/[0-9]//g')
  23.  
  24. # runs time function for the called script, output in a comma seperated
  25. # format output file specified with -o command and -a specifies append
  26. /usr/bin/time -f "%E,%U,%S" -o ${output_file} -a ${command_to_run} > /dev/null 2>&1
  27.  
  28. echo -ne ${l}' ('${p}'%) \r'
  29. done;
  30.  
  31. echo -ne '\n'
  32.  
  33. # Convenience seperator for file
  34. #echo '--------------------------' >> $output_file
  35. }
  36.  
  37. # Option parsing
  38. while getopts n:c:o: OPT
  39. do
  40. case "$OPT" in
  41. n)
  42. repeats=$OPTARG
  43. ;;
  44. o)
  45. output_file=$OPTARG
  46. ;;
  47. c)
  48. command_to_run=$OPTARG
  49. run_tests
  50. ;;
  51. \?)
  52. echo 'No arguments supplied'
  53. exit 1
  54. ;;
  55. esac
  56. done
  57.  
  58. shift `expr $OPTIND - 1`
Add Comment
Please, Sign In to add comment