Created
July 2, 2019 10:48
-
-
Save mrchimp/8ccda29c2db2320ac8746f52e19466cd to your computer and use it in GitHub Desktop.
Get average response time for a given url
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Usage: | |
| # ./times.sh http://example.com | |
| # Number of requests to make. You can up this if for a more accurate result | |
| n=20 | |
| # The URL we will be accessing | |
| url=$1 | |
| # The response times as strings | |
| values=() | |
| for ((i=0; i < $n; i++)); | |
| do | |
| # Make an HTTP response and get the total time it took | |
| value=$(curl -so /dev/null -w '%{time_total}\n' $url) | |
| # Output that time so that we can see it | |
| echo $value | |
| # Add it to the list of times | |
| values+=($value) | |
| done | |
| # Sum up all of the times using bc because bash doesn't do floating point | |
| sum=$(echo "${values[@]/%/+} 0" | bc -l) | |
| # Compute and output the average | |
| echo Average: | |
| echo "$sum / $n" | bc -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment