How to test a website loading speed using the curl command

If you need an accurate measurement of how fast (or slow) 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 fast (or slow) your websites load, give the curl command a try.

If you are a web administrator, data can be your best friend. Unique visitors, browser IDs, 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, rejection rate, exit pages – these are statistics that can give you power in so many encounters with people above you in the command structure.

But what about the statistics that help you do your job? Such a statistic is the loading speed of websites. If your site loads slowly, you will have frustrated customers and customers. How do you measure the loading time of your site? Of course you can point your browser to the page and click on a stopwatch. But to do that effectively, you must first clear your browser’s cache, otherwise you will get inaccurate data.

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

One way to read the loading time of the site more accurately is by using the curl command. Curl is a tool used to transfer data via various protocols. This allows us to 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 is completed on the remote server (time_connect)

  • Time when file transfer started (time_pretransfer)

  • The time at which the first byte was to be sent to the external server (time_starttransfer)

  • Time used to complete the response (time_total)

What you need

The only things you need to make this work are:

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

  • A website for testing

I will demonstrate on Pop! _OS Linux.

How to install curl

Chances are that your Linux distribution contains standard curl. If this is not the case, it is found in the standard repositories and can be installed with commands such as:

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

Use

With curl installed, we can now execute the order to test the loading time of your site. Although the command to test five different times is long, it is actually quite easy to understand. The command itself is:

curl -s -w ‘Website Test 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 the URL or IP address of the website being tested.

The three options used are:

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

The output of the command is displayed in an easily readable format (Figure A).

Figure A

The assignment’s execution is performed on a copy of Nextcloud.

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

This command would be:

curl -s -w ‘Website Test 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 displayed in Figure B.

Figure B

HTTPS website load time test with curls.

Create a simpler command

You can do this command considerably more easily by creating a curly layout file and then giving the command that calls the file. Here’s how. First create a file with the command:

nano ~ / curl-formatting.txt

Paste the following into that file:

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
———- n
time_total:% {time_total} n

Save and close the file.

Now execute the command as follows:

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

Where ADDRESS is the URL or IP address of the site being tested.

The output must be the same as when you run the command with all inline options (Figure C).

Figure C

The command output is similar.

And so you can get a more accurate measurement of how quickly your websites are loaded. Discover how you can get even more out of curl with the command man curl.

Open source weekly newsletter

You do not want to miss our tips, tutorials and comments about the Linux operating system and open source applications.
Delivered Tuesday

Register today

Also see

Image: iStockphoto / metamorworks

The five best iPhone deals from Black Friday are still live: iPhone 12, 11, SE and more

Home News Mobile Phones (Image credit: Future) Black Friday might now technically be over but that doesn't mean you can't still grab one of those glorious Black Friday iPhone deals that were circulating the web on Friday.In fact, most of the iPhone deals that really blew us away are still going strong. Big price cuts,…

These iPhone 11 deals ruled over Black Friday and are still available right now

Home News Mobile Phones (Image credit: Future) If you spent anytime on Black Friday looking at iPhone 11 deals, you'll already know that it had the cheapest prices we've ever seen on the fantastic handset. And if you didn't get a chance to make the purchase then don't worry, you haven't lost your chance.Black Friday…

This Week in Apps: Snapchat clones TikTok, India bans 43 Chinese apps, more information on App Shop commission modifications

Welcome back to This Week in Apps, the TechCrunch series that recaps the latest in mobile OS news, mobile applications, and the overall app economy. The app industry is as hot as ever, with a record 204 billion downloads and $120 billion in consumer spending in 2019. People now spend three hours and 40 minutes per day using apps,…

Leave a Reply