Get timing details with curl command

It is sometimes useful to get the timing details of a curl request, for analysis, investigation or just monitoring. Thanks to curl implementation, there’s an easy way to get timing details.

This can be done with two ways: a formatting file or directly on command line. We will explore both solutions below.

Formatting file:

You’ll first need to create a new file format.txt and put this in:

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

Then, you need to make a curl request to your website:

curl -w "@format.txt" -o /dev/null -s https://microsoft.com/

Here are the options being used:

  • -w "@format.txt" to use the right file for formatting
  • -o /dev/null to redirect output to nowhere
  • -s to make curl silent

And here is the output:

time_namelookup: 0.010966
time_connect: 0.039054
time_appconnect: 0.059524
time_pretransfer: 0.059618
time_redirect: 0.000000
time_starttransfer: 0.073602

time_total: 0.07364

Command-line:

The command-line will use same kind of parameters, but directly on the CLI instead of using a file. It would result in a command like this to get the same kind of output as shown above:

curl -w "time_namelookup: %{time_namelookup}\ntime_connect: %{time_connect}\ntime_appconnect: %{time_appconnect}\ntime_pretransfer: %{time_pretransfer}\ntime_redirect: %{time_redirect}\ntime_starttransfer: %{time_starttransfer}\n\ntime_total: %{time_total}\n" -o /dev/null -s https://microsoft.com