Skip to content

Instantly share code, notes, and snippets.

@josephscott
Last active May 19, 2021 21:19
Show Gist options
  • Save josephscott/8c2f15b55ba6856489aec0ca8ecf1a03 to your computer and use it in GitHub Desktop.
Save josephscott/8c2f15b55ba6856489aec0ca8ecf1a03 to your computer and use it in GitHub Desktop.
Get the app response TTFB ( Time To First Byte ) with curl
#!/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