Take the 2-minute tour ×

I have a web service that receives data in JSON format, processes the data, and then returns the result to the requester.

I want to measure the request, response, and total time using cURL.

My example request looks like:

curl -X POST -d @file server:port

and I currently measure this using the time command in Linux:

time curl -X POST -d @file server:port

The time command only measures total time, though - which isn't quite what I am looking for.

Is there any way to measure request and response times using cURL?

share|improve this question

2 Answers 2

up vote 81 down vote accepted

From this brilliant blog post... https://josephscott.org/archives/2011/10/timing-details-with-curl/

cURL supports formatted output for the details of the request (see the cURL manpage for details, under -w, –write-out <format>). For our purposes we’ll focus just on the timing details that are provided.

  1. Create a new file, curl-format.txt, and paste 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
             time_total:  %{time_total}\n
  2. Make a request:

    curl -w "@curl-format.txt" -o /dev/null -s "http://wordpress.com/"

    Or on Windows, it's...

    curl -w "@curl-format.txt" -o NUL -s "http://wordpress.com/"

What this does:

-w "@curl-format.txt" tells cURL to use our format file
-o /dev/null redirects the output of the request to /dev/null
-s tells cURL not to show a progress meter
"http://wordpress.com/" is the URL we are requesting. Use quotes particularly if your URL has "&" query string parameters

And here is what you get back:

   time_namelookup:  0.001
      time_connect:  0.037
   time_appconnect:  0.000
  time_pretransfer:  0.037
     time_redirect:  0.000
time_starttransfer:  0.092
        time_total:  0.164

Make a Windows shortcut (aka BAT file)

Put this command in CURLTIME.BAT (in the same folder as curl.exe)

curl -w "@%~dp0curl-format.txt" -o NUL -s %*

Then you can simply call...

curltime wordpress.org
share|improve this answer
awesome answer. thank you. one thing that i had to do was adding \n to break the line in the text file –  dmtri.com May 2 at 19:51
In the windows BAT file it only sends the first parameter, change to this to pass all parameters and to disable echo the command it self: @curl -w "@%~dp0curl-format.txt" -o NUL -s %* Great answer –  padilo -aka udoh- Oct 1 at 15:52
Thanks @udoh, I've updated the answer to include that. –  Simon Oct 2 at 1:09
excellent answer. how do i also include the current date+time of when the curl initiated the request? –  Saqib Ali Dec 13 at 16:25

It looks like I was using the wrong words - when I ask for request/response (as opposed to upload/download), I get a ton of hits.

Here is the answer:

curl -X POST -d @file server:port -w %{time_connect}:%{time_starttransfer}:%{time_total}

All of the variables used with -w can be found in man curl.

share|improve this answer

Your Answer


