How to Test Website Loading Speed in Linux

The website loading speed or response time is very important for any webmaster because it will impact search engine rankings and user experience. So if you are a system administrator or webmaster then it is important for you to test your website speed and take immediate action to speed up it. There are several web-based and command-line tools available to test your website speed.

In this tutorial, we will show you how to test website loading speed using the curl command in Linux.

Test Website Speed with Curl

Curl is a simple yet powerful tool to transfer data to and from a server. It is also used to test the response time using the different variables.

Lets test the loading speed of the website https://www.howtoforge.com.

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 https://www.howtoforge.com

You should get the following output:

Testing Website Response Time for :https://www.howtoforge.com/

Lookup Time:		0.511
Connect Time:		0.565
Pre-transfer Time:	0.565
Start-transfer Time:	0.726

Total Time:		0.727

A brief explanation of each option is shown below:

  • time_connect - Display the time in seconds from the connect was noticed by curl until the first byte arrived.
  • time_namelookup - Display the time in seconds it took from the start until the name resolving was completed.
  • time_pretransfer - Display the time in seconds it took from the start until the file transfer was just about to begin.
  • time_starttransfer - Display the time in seconds from the connect was noticed by curl until the first byte arrived.
  • time_total - The total time in seconds to perform the operation.
  • -s - Don't display the progress bar.
  • -w - Used to define what to display on output.
  • -o - Used to write complete output to /dev/null.

If your website is HTTPS, you can run the following command:

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 https://www.howtoforge.com

You should get the following output:

Testing Website Response Time for :https://www.howtoforge.com/

Lookup Time:		0.511
Connect Time:		0.564
AppCon Time:		0.724
Redirect Time:		0.000
Pre-transfer Time:	0.724
Start-transfer Time:	1.085

Total Time:		1.264

If you don't want to run a long command every time, you can create a file named curl_test.txt and all required options:

nano curl_test.txt

Add the following lines:

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 then run the following command:

curl -w "@curl_test.txt" -o /dev/null -s https://www.howtoforge.com

You should get the following output:

time_namelookup:  0.013
time_connect:  0.056
time_appconnect:  0.160
time_pretransfer:  0.160
time_redirect:  0.000
time_starttransfer:  0.511
----------
time_total:  0.753

You can just replace www.howtoforge.com with your website name or IP address to test the website speed.

Conclusion

In the above guide, you learned how to test website loading speed using the Curl command. I hope this will helps you to test the speed of your website.

Share this page:

Suggested articles

4 Comment(s)

Add comment

Comments

By: Petter Neumann at: 2021-04-16 10:22:14

Just for fun, I did test my small website, running Raspberrypi 4 - 4gb, Ubuntu 20.10 server, Nginx, Maria db and Thirtybees. The Raspberrypi have a Samsung T5 USB3 SSD drive:

Lookup Time:        0,004341Connect Time:        0,004652Pre-transfer Time:    0,004681Start-transfer Time:    0,040646Total Time:        0,040689

I was testing from the same network as the Raspberry Pi is located to the test only reflects the performance of the small raspberry, but I'm impressed :-)

By: Joe at: 2021-04-16 18:51:38

Your results tell me you tested it more than once and your curl pulled the data from your cache. Those are not real values. To avoid that, you may want to add ?put_random_text_here at the end of each URL to avoid caching (at least for some servers - doesn't work always, but mostly it should work).E.g. yourdomain(dot)com?agf317

By: Dave's Not Here at: 2021-04-16 16:31:50

time_namelookup:  0.000993time_connect:  0.002293time_appconnect:  0.000000time_pretransfer:  0.002321time_redirect:  0.000000time_starttransfer:  0.003280

1 vCPU, 1GB RAM, static website with a reverse nginx proxy for about 20 other domains running under a KVM VM.

By: Dave's Not Here at: 2021-04-16 16:32:48

Maybe using the 'ab' tool would be more useful?