Measure website Latency using cURL

Whenever we build a new website, we need to know the latency of the website.
That means we need to know the timing details to load the web page.

For our purposes we will use the timing details that are provided by cURL as it supports formatted output for the details of the request.

Step 2 : create a new file, time-format.txt, and paste in:

time_namelookup: %{time_namelookup}
time_connect: %{time_connect}
time_appconnect: %{time_appconnect}
time_pretransfer: %{time_pretransfer}
time_redirect: %{time_redirect}
time_starttransfer: %{time_starttransfer}
———
time_total: %{time_total}

Step 1 : make a request:

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

What this does:

-w@time-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
https://thegnulinuxguy.com/ is the URL we are requesting

Below is the output we will get

time_namelookup: 0.168486
time_connect: 0.448887
time_appconnect: 0.965902
time_pretransfer: 0.965935
time_redirect: 0.000000
time_starttransfer: 1.268384
----------
time_total: 1.268546

time_appconnect : The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.

time_connect : The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.

time_namelookup : The time, in seconds, it took from the start until the name resolving was completed.

time_pretransfer : The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.

time_redirect : The time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections.

time_starttransfer : The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.

time_total : The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.

The format file for this output provides a reasonable level of flexibility, for instance you could make it CSV formatted for easy parsing. You might want to do that if you were running this as a cron job to track timing details of a specific URL.

For details on the other information that cURL can provide using -w check out the cURL manpage.

Leave a Reply