Skip to content

Instantly share code, notes, and snippets.

@pixmin
Created August 29, 2019 13:41
Show Gist options
  • Save pixmin/588e381743634f579bd4e0891e60cdde to your computer and use it in GitHub Desktop.
Save pixmin/588e381743634f579bd4e0891e60cdde to your computer and use it in GitHub Desktop.
Time to load page
#!/bin/bash
# To decide how many times the test should be run:
# perf <n> <url>
#
# Otherwise simply use
# perf <url>
DEFAULT_RUN=10
if [[ $1 =~ ^-?[0-9]+$ ]]
then
COUNT=$1
URL=$2
else
COUNT=$DEFAULT_RUN
URL=$1
fi
TOTAL=0
for ((i=1;i<=COUNT;i++))
do
TIME=`curl -w "%{time_total}\n" -o /dev/null -s "$URL"`
TOTAL=`echo $TOTAL + $TIME | bc`
echo $TIME
done
# Int
# AVERAGE=$(echo "$TOTAL / $COUNT" | bc)
# Float
AVERAGE=$(awk "BEGIN {printf \"%.4f\",${TOTAL}/${COUNT}}")
echo -e "\nAverage after $COUNT runs: $AVERAGE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment