Created
January 31, 2014 17:25
-
-
Save PHLAK/8737364 to your computer and use it in GitHub Desktop.
Test average response times for jQuery from Google and jQuery CDNs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Set the url | |
if [[ "$1" == "google" ]]; then | |
URL="ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js" | |
elif [[ "$1" == "jquery" ]]; then | |
URL="code.jquery.com/jquery-2.0.3.min.js" | |
else | |
echo "Usage: $0 { google | jquery } [ ITTERATIONS ]" | |
exit 1 | |
fi | |
## Echo status | |
echo -n "Calculating ..." | |
## Default | |
TOTAL_TIME=0 | |
if [[ $2 > 0 ]]; then | |
while [[ $COUNTER -lt $2 ]]; do | |
## Start timer | |
TIMER_START=$(date +%s%N) | |
## Fetch jQuery | |
wget -q -O /dev/null --no-cache https://$URL | |
## Stop timer | |
TIMER_STOP=$(date +%s%N) | |
## Set request time | |
TIME=$((($TIMER_STOP - $TIMER_START ) / 1000000)) | |
## Store total for later calculation | |
TOTAL_TIME=$(($TOTAL_TIME + $TIME)) | |
## Echo current time | |
echo -n " ${TIME}" | |
## Increment counter | |
((COUNTER++)) | |
## Sleep | |
sleep 1 | |
done | |
else | |
echo "Usage: $0 { google | jquery } [ ITTERATIONS ]" | |
exit 1 | |
fi | |
## Calculate average | |
AVERAGE=$(($TOTAL_TIME / $2)) | |
echo | |
echo "Average response time: ${AVERAGE} milliseconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment