benchmark.sh 910 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh
  2. set -eu
  3. command -v php >/dev/null 2>&1 || { echo "I require \`php\` but it's not available. Aborting." >&2; exit 255; }
  4. command -v grep >/dev/null 2>&1 || { echo "I require \`grep\` but it's not available. Aborting." >&2; exit 255; }
  5. command -v awk >/dev/null 2>&1 || { echo "I require \`awk\` but it's not available. Aborting." >&2; exit 255; }
  6. BRANCH1=${1:-''}
  7. BRANCH2=${2:-''}
  8. if [ "" = "$BRANCH1" ] || [ "" = "$BRANCH2" ];
  9. then
  10. echo "Usage: bash benchmark.sh BRANCH1 BRANCH2 ...BRANCHN"
  11. exit 1;
  12. fi
  13. for BRANCH in "$@"
  14. do
  15. git checkout "$BRANCH" > /dev/null 2>&1 &&
  16. git reset --hard > /dev/null 2>&1 &&
  17. printf '%s' "$BRANCH"
  18. (for _ in $(seq 1 10); do php php-cs-fixer fix --dry-run 2> /dev/null ; done) | grep -i seconds | awk '
  19. {
  20. total += $5;
  21. ++count;
  22. }
  23. END {
  24. print " mean:" (total/count) " total:" total " rounds:" count
  25. }'
  26. done