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 Watch Now

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

Usage

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}



Lookup Time:\t\t%{time_namelookup}

Connect Time:\t\t%{time_connect}

Pre-transfer Time:\t%{time_pretransfer}

Start-transfer Time:\t%{time_starttransfer}



Total Time:\t\t%{time_total}

' -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

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}



Lookup Time:\t\t%{time_namelookup}

Connect Time:\t\t%{time_connect}

AppCon Time:\t\t%{time_appconnect}

Redirect Time:\t\t%{time_redirect}

Pre-transfer Time:\t%{time_pretransfer}

Start-transfer Time:\t%{time_starttransfer}



Total Time:\t\t%{time_total}

' -o /dev/null ADDRESS

The results of this command are shown in Figure B.

Figure B

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}

time_connect: %{time_connect}

time_appconnect: %{time_appconnect}

time_pretransfer: %{time_pretransfer}

time_redirect: %{time_redirect}

time_starttransfer: %{time_starttransfer}

----------

time_total: %{time_total}



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

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.

Open Source Weekly Newsletter You don't want to miss our tips, tutorials, and commentary on the Linux OS and open source applications. Delivered Tuesdays Sign up today

Also see