Skip to content

Instantly share code, notes, and snippets.

@sandeepraju
Created July 20, 2016 21:17
Show Gist options
  • Save sandeepraju/1f5fbdbdd89551ba7925abe2645f92b5 to your computer and use it in GitHub Desktop.
Save sandeepraju/1f5fbdbdd89551ba7925abe2645f92b5 to your computer and use it in GitHub Desktop.
curl command to check the time to first byte
#!/bin/bash
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -o /dev/null \
-H 'Cache-Control: no-cache' \
-s \
-w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" \
$1
@vaclav-kasal
Copy link

vaclav-kasal commented Feb 15, 2018

With -Iz I get bad numbers(zeroes). I use seq 10 | xargs -n 1 ttfb google.com and works as expected.

@jaygooby
Copy link

Thanks for this @sandeepraju!

I've turned it into a more fully fledged utility here: https://github.com/jaygooby/ttfb.sh

@torlenor
Copy link

torlenor commented Jan 2, 2020

Thanks!

@alive-vietnam-ti
Copy link

Thanks!

@kubrt-d
Copy link

kubrt-d commented Mar 17, 2021

Just what I needed, thanks !

@Ynniss
Copy link

Ynniss commented Jun 21, 2021

Awesome !

@rc452860
Copy link

Thanks!

@moly7x
Copy link

moly7x commented May 25, 2023

Thanks

@dunklesToast
Copy link

If somebody needs it:

seq 50 | xargs -Iz ./ttfb.sh "url" | awk '{sum+=$NF; count++} END {print "Sum of Total time:", sum; print "Average Total time:", sum/count}'

outputs the average total time like this:

Sum of Total time: 8.07832
Average Total time: 0.161566

@jaygooby
Copy link

@dunklesToast with my fork you can run ttfb -n 50 example.com/example/url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment