Last active
November 15, 2020 05:46
-
-
Save siberex/9adb939b1c7872404672697ee7985188 to your computer and use it in GitHub Desktop.
Measure average response time for each of provided URLs
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
#!/usr/bin/env bash | |
set -euo pipefail | |
# For a set of provided URLs, measure average response time for each one. | |
# https://gist.github.com/siberex/9adb939b1c7872404672697ee7985188 | |
NUM_REQUESTS=100 | |
URLS=() | |
while IFS='' read -r line; do URLS+=("$line"); done < <(cat << END_OS_LIST | |
be.ololo.li | |
ch.ololo.li | |
de.ololo.li | |
uk.ololo.li | |
us.ololo.li | |
hk.ololo.li | |
jp.ololo.li | |
kr.ololo.li | |
END_OS_LIST | |
) | |
for link in ${URLS[*]}; do | |
url=$(echo | awk -v url="$link" 'BEGIN {OFS=""} {if (url ~ /^https?:\/\//) print url; else print "https://", url}') | |
req_time_sum=0 | |
for (( i=1; i<=NUM_REQUESTS; i++ )); do | |
# Measure either %{time_starttransfer} or %{time_total} | |
req_time=$(curl -s -o /dev/null -w "%{time_total}" "$url" | sed 's/,/\./') | |
#echo "$req_time" | |
req_time_sum=$(awk "BEGIN{ print $req_time_sum + $req_time }" | sed 's/,/\./') | |
done | |
req_avg_time=$(awk "BEGIN{ print $req_time_sum / $NUM_REQUESTS }") | |
printf "%s\t%s\n" "$link" "$req_avg_time" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment