Timing Request with cURL

We can use cURL to measure request time consumed during the whole process, such as DNS lookup, TCP handshake, SSL handshake time:

curl https://www.aldoraweb.com/ \
  -s --connect-timeout 5 \
  -o /dev/null \
  -w "%{time_namelookup} %{time_connect} %{time_appconnect} %{time_pretransfer} %{time_starttransfer} %{time_total}" |
awk '{print "DNS Lookup: " $1 "s\n" "TCP Handshake: " $2-$1 "s\n" "SSL Handshake: " $3-$2 "s\n" "Wait: " $5-$4 "s\n" "Data Transfer: " $6-$5 "s\n"}'

Output:

DNS Lookup: 0.005691s
TCP Handshake: 0.096365s
SSL Handshake: 0.239081s
Wait: 1.07219s
Data Transfer: 0.001439s

As A Question of Timing shows, we can measure request timing using cURL:

cURL is an excellent tool for debugging web requests, and it includes the ability to take timing measurements. ... These timings are in seconds. Depending on your version of cURL, you may get more decimal places than this example. 3 seconds is a long time, and remember this is only for the HTML from the home page - it doesn’t include any JavaScript, images, etc.

timing-with-curl

cURL shows us the timing of requests through variables like time_namelookup, time_connect, and we can get TCP handshake time by using time_connect - time_namelookup, get SSL handshake time by using time_appconnect - time_connect, etc.,

curl https://www.aldoraweb.com/ \
  -s --connect-timeout 5 \
  -o /dev/null \
  -w "
time_namelookup: %{time_namelookup}s
time_connect: %{time_connect}s
time_appconnect: %{time_appconnect}s
time_pretransfer: %{time_pretransfer}s
time_starttransfer: %{time_starttransfer}s
time_total: %{time_total}s\n"

Output:

time_namelookup: 0.006820s
time_connect: 0.106716s
time_appconnect: 0.481996s
time_pretransfer: 0.482142s
time_starttransfer: 1.208604s
time_total: 1.394630s

If you want to know more about the above script, I recommend using: