How to test a website loading speed using the curl command

If you need an accurate measurement of how quickly (or slowly) your websites load, give the curl command a try.

How to test a website loading speed using the curl command If you need an accurate measurement of how quickly (or slowly) your websites load, give the curl command a try.

If you're a web admin, data can be your best friend. Unique visitors, browser identifiers, value per visit, cost per conversion, conversion rates, total number of sessions or visits, top pages, traffic sources, time spent on site, interactions per visit, bounce rate, exit pages--these are metrics which can empower you in those many meetings with those above you in the chain of command.

But what about the metrics that help you do your job? One such metric is website loading speed. If your site is slow to load, you're going to have frustrated customers and clients. How do you measure the load time of your site? Sure, you could point your browser to the page and click a stopwatch. But to do that effectively, you'd have to first clear your browser's cache, otherwise you'll get inaccurate data. 

SEE: 10 free alternatives to Microsoft Word and Excel (TechRepublic download)

One way to get a more accurate reading of site load time is by using the curl command. Curl is a tool used to transfer data via various protocols. With it we can time the loading of a website with considerable accuracy. 

With this command we can see:

  • Total time before a request received a response (time_namelookup)

  • Total time when the TCP protocol was completed on the remote server (time_connect)

  • Time when file transfer was started (time_pretransfer)

  • The time the first byte was to be transmitted to the remote server (time_starttransfer)

  • Time used to complete the response (time_total)

What you'll need

The only things you'll need to make this work are:

  • The curl command (which can be installed on Linux, Windows, and macOS)

  • A website to test

I'll be demonstrating on Pop!_OS Linux. 

How to install curl

Chances are your Linux distribution includes curl by default. If not, it's found in the standard repositories and can be installed with commands like:

sudo apt-get install curl -y
sudo dnf install curl -y


With curl installed, we can now run the command to test load time of your site. Although the command to test for the five different times is long, it's actually quite easy to understand. The command itself is:

curl -s -w 'Testing Website Response Time for :%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null ADDRESS

Where ADDRESS is either the URL or IP address of the website to be tested.

The three options used are:

  • -s - will show an error if the command fails
  • -w - make curl display results of the command in the terminal window (stdout)
  • -o - output to a file

The output of the command will display in an easy to read format (Figure A).

Figure A


The output of the command run on an instance of Nextcloud.

If your site uses HTTPS, you can add the following:

  • Time measured for the entire SSL communication process (time_appconnect).

  • Time measured for redirection (time_redirect).

This command would be:

curl -s -w 'Testing Website Response Time for :%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null ADDRESS

The results of this command are shown in Figure B.

Figure B


Testing HTTPS website load time with curl.

How to create an easier command

You could make this command considerably easier to run by creating a curl formatting file and then issuing the command calling the file. Here's how. First, create a file with the command:

nano ~/curl-formatting.txt

In that file, paste the following:

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

Save and close the file. 

Now run the command like so:

curl -w "@curl-format.txt" -o /dev/null -s ADDRESS

Where ADDRESS is either the URL or IP address of the site to be tested.

The output should be the same as if you ran the command with all of the options inline (Figure C).

Figure C


The command output looks similar.

And that's how you can get a more accurate measure of how quickly your websites are loading. Find out how you can get even more out of curl with the command man curl.

Also see

Communication network concept. Smart office. Internet business.

Image: iStockphoto/metamorworks