Last active
May 19, 2021 21:19
-
-
Save josephscott/8c2f15b55ba6856489aec0ca8ecf1a03 to your computer and use it in GitHub Desktop.
Get the app response TTFB ( Time To First Byte ) with curl
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 | |
set -eu | |
export LC_ALL=C.UTF-8 | |
CURL_FORMAT="%{time_starttransfer} - %{time_pretransfer}" | |
declare -a TIMES | |
for i in {1..15}; do | |
OUT_CURL=$(curl -w "$CURL_FORMAT" -k --compressed -s -o /dev/null "$@") | |
echo -n "." | |
TIMES[i]=$(echo "$OUT_CURL" | bc) | |
done | |
echo | |
IFS=$'\n' SORTED_TIMES=($(sort <<<"${TIMES[*]}")); unset IFS | |
echo "fastest: ${SORTED_TIMES[0]} slowest: ${SORTED_TIMES[@]: -1: 1}" | |
printf "p50: %f\n" "${SORTED_TIMES[@]: -7: 1}" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment