Skip to content

Instantly share code, notes, and snippets.

@andreloureiro
Last active October 1, 2021 12:53
Show Gist options
  • Save andreloureiro/9dc907109da3f2dd35fc1610a716181a to your computer and use it in GitHub Desktop.
Save andreloureiro/9dc907109da3f2dd35fc1610a716181a to your computer and use it in GitHub Desktop.
Latency percentile
#!/bin/bash
# ntimes: https://github.com/yuya-takeyama/ntimes - or `repeat` if using zsh
# percentile: https://github.com/yuya-takeyama/percentile
# usage: ttfb URL [TIMES] | percentile
TIMES=${2:-100}
(ntimes $TIMES -- \
curl $1 \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'accept-language: en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7' \
--compressed -s -o /dev/null -w "%{time_starttransfer}\n" | sed "s/\,/\./") | percentile
# Results:
# ❯ ./ttfb.sh https://site.gympass.com 1000
# 50%: 0.120782
# 66%: 0.123328
# 75%: 0.124996
# 80%: 0.125849
# 90%: 0.129709
# 95%: 0.134144
# 98%: 0.141621
# 99%: 0.154519
# 100%: 0.632481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment