How To Find Response Time Using CURL Request

Using CURL, you can find the response time of a request. You need to have a custom template to get the response time. Follow the steps given below.

Step 1: Create a file name curl-format.txt and copy the following template on to the file.

{\n
"time_redirect": %{time_redirect},\n
"time_namelookup": %{time_namelookup},\n
"time_connect": %{time_connect},\n
"time_appconnect": %{time_appconnect},\n
"time_pretransfer": %{time_pretransfer},\n
"time_starttransfer": %{time_starttransfer},\n
"time_total": %{time_total},\n
"size_request": %{size_request},\n
"size_upload": %{size_upload},\n
"size_download": %{size_download},\n
"size_header": %{size_header}\n
}\n

Step 2: Use the following format to make the curl request.

curl -v -w "@curl-format.txt"  <request URL>

For example,

curl -v -w "@curl-format.txt"  http://myapp.com/api/v1/members

A resposne output would look like the following.

{"error":{"errorCode":"3001","message":"Unauthorized request."}}{
"time_redirect": 0.000,
"time_namelookup": 0.000,
"time_connect": 0.002,
"time_appconnect": 0.000,
"time_pretransfer": 0.002,
"time_starttransfer": 0.026,
"time_total": 0.026,
"size_request": 109,
"size_upload": 0,
"size_download": 64,
"size_header": 106
}

time_total is the total response time.

CURL with Headers

Also, you can add headers to the curl request using the following syntax.

curl -v -w "@curl-format.txt"   -H "user: username" -H "api-token: sdf^&%hsdjfh" -H "Accept: application/json" http://myapp.com/api/v1/members

CURL with proxy

To add a proxy to your curl request, you can use the following syntax

curl -v -w "@curl-format.txt"   -H "user: username" -H "api-token: sdf^&%hsdjfh" -H "Accept: application/json" --proxy http://<proxy-url>:<proxy-port> http://myapp.com/api/v1/members