benchmark.sh 930 B

12345678910111213141516171819202122232425262728293031
  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: ./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. composer update -q
  19. (for _ in $(seq 1 10); do php php-cs-fixer fix --dry-run 2> /dev/null ; done) | grep -i seconds | awk '
  20. {
  21. total += $5;
  22. ++count;
  23. }
  24. END {
  25. print " mean:" (total/count) " total:" total " rounds:" count
  26. }'
  27. done