Last active
April 7, 2018 07:13
-
-
Save coord-e/b0e9b303686a8f50d45da0e5815c3565 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Copyright © 2018 coord.e | |
# This work is free. You can redistribute it and/or modify it under the | |
# terms of the Do What The Fuck You Want To Public License, Version 2, | |
# as published by Sam Hocevar. See the COPYING file for more details. | |
ITERATION_NUM=20 | |
CANDIDATES=("ifconfig.me" "icanhazip.com" "ipinfo.io/ip" "checkip.amazonaws.com" "inet-ip.info" "httpbin.org/ip" "ifconfig.co") | |
declare -A RESULTS | |
for idx in $(seq $ITERATION_NUM); do | |
echo -ne "Iteration $(printf %02d $idx)" | |
for item in ${CANDIDATES[@]}; do | |
elapsed=$(TIMEFORMAT='%3R'; { time curl -s $item > /dev/null ; } 2>&1 | tr -d '\n') | |
if [ $idx -eq 1 ]; then | |
RESULTS[$item]=$elapsed | |
else | |
RESULTS[$item]=$(bc <<< ${RESULTS[$item]}+$elapsed) | |
fi | |
echo -n '.' | |
done | |
echo | |
sleep 5 | |
done | |
echo "Done." | |
for item in ${!RESULTS[@]}; do | |
average=$(bc <<< "scale=4; ${RESULTS[$item]}/$ITERATION_NUM") | |
echo -e "$item:\t$average" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment