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

curl -s -w 'Testing Website Response Time for :%{url_effective}nnLookup Time:tt%{time_namelookup}nConnect Time:tt%{time_connect}nPre-transfer Time:t%{time_pretransfer}nStart-transfer Time:t%{time_starttransfer}nnTotal Time:tt%{time_total}n' -o /dev/null http://www.howtoforge.com

You should get the following output:

Testing Website Response Time for :http://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}nnLookup Time:tt%{time_namelookup}nConnect Time:tt%{time_connect}nAppCon Time:tt%{time_appconnect}nRedirect Time:tt%{time_redirect}nPre-transfer Time:t%{time_pretransfer}nStart-transfer Time:t%{time_starttransfer}nnTotal Time:tt%{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.