Curl – Request and Response Times

I had again the need to calculate proxy performance.

So a few notes on this topic.

Time to First Byte Using Curl

Jon Fox published an post how to find the time to first byte (TTFB) with curl.

curl -w "Connect time: %{time_connect} Time to first byte: %{time_starttransfer} Total time: %{time_total} \n" -o /dev/null [url to test]

Joseph Scott extended this in his port. https://blog.josephscott.org/2011/10/14/timing-details-with-curl/

  1. Time to First Byte Using Curl
  2. Create the file curl-format.txt with this content
  3. Make a request
  4. A stand-alone script
  5. Links

Create the file curl-format.txt with this content

       content_type:  %{content_type}\n
          http_code:  %{http_code} \n
       http_connect:  %{http_connect} \n
       num_connects:  %{num_connects} \n
      num_redirects:  %{num_redirects} \n
\n
    time_namelookup:  %{time_namelookup}s\n
       time_connect:  %{time_connect}s\n
    time_appconnect:  %{time_appconnect}s\n
   time_pretransfer:  %{time_pretransfer}s\n
      time_redirect:  %{time_redirect}s\n
 time_starttransfer:  %{time_starttransfer}s\n
                    ----------\n
         time_total:  %{time_total}s\n


Make a request

curl -w "@curl-format.txt" -o /dev/null -s "https://pp52.de/"

A stand-alone script

#!/bin/bash

curl -w @- -o /dev/null -s "$@" <<'EOF'
    time_namelookup:  %{time_namelookup}\n
       time_connect:  %{time_connect}\n
    time_appconnect:  %{time_appconnect}\n
   time_pretransfer:  %{time_pretransfer}\n
      time_redirect:  %{time_redirect}\n
 time_starttransfer:  %{time_starttransfer}\n
                    ----------\n
         time_total:  %{time_total}\n
EOF