How to Test Website Loading Speed in Linux Terminal

A website response time can have a great impact on user experience, and if you are a web developer, or simply a server administrator who is particularly responsible for organizing the pieces together, then you have to make it a point that users don’t feel frustrated while accessing your site – so there is really “need for speed”.

Read Also: httpstat – A Curl Statistics Tool to Check Website Performance

This guide will show you how to test a website response time from the Linux command line. Here, we will show how to check the time in seconds, it takes:

  • to perform name resolution.
  • for TCP connection to the server.
  • for the file transfer to begin.
  • for the first byte to be transferred.
  • for the complete operation.

Additionally, for HTTPS-enabled sites, we will also see how to test the time, in seconds, it takes: for a redirect, and SSL connection/handshake to the server to be completed. It sounds good right, okay, let’s get started.

cURL is a powerful command line tool to transfer data from or to a server, using protocols such as FILE, FTP, FTPS, HTTP, HTTPS and many others. In most cases, it is used as a command line downloader, or for checking HTTP headers. However, here, we will describe one of its lesser-known functionalities.

cURL has a useful option: -w for printing information on stdout after a completed operation. It has some variables that we can use to test the different response times listed above, of a website.

We will use some of the time-related variables, which can be passed in a given format as a literal string or inside a file.

So open your terminal and run the command below:

$ 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
Test Website Loading Speed
Test Website Loading Speed

The variables in the above format are:

  • time_namelookup – time, in seconds, it took from the start until the name resolving was completed.
  • time_connect – time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
  • time_pretransfer – time, in seconds, it took from the start until the file transfer was just about to begin.
  • time_starttransfer – time, in seconds, it took from the start until the first byte was just about to be transferred.
  • time_total – total time, in seconds, that the full operation lasted (millisecond resolution).

If the format is too long, you can write it in a file and use the syntax below to read it:

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

In the above command, the flag:

  • -s – tells curl to work silently.
  • -w – print the information on stdout.
  • -o – used to redirect output (here we discard the output by redirecting it to /dev/null).

For HTTPS sites, you can run the command below:

$ 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
Test HTTPS Website Speed
Test HTTPS Website Speed

In the above format, the new time variables are:

  • time_appconnect – time, in seconds, it took from the start until the SSL connect/handshake to the remote host was completed.
  • time_redirect – time, in seconds, it took for all redirection steps including name lookup, connect, pretransfer and transfer before the final transaction was started; it computes the full execution time for multiple redirections.

Important points to be noted.

  • You will notice that the response time values keep on changing (due to several factors) as you run different tests, therefore it is advisable to collect several values and get an average speed.
  • Secondly, from the results of the commands above, you can see that accessing a website over HTTP is much faster than over HTTPS.

For more information, see the cURL man page:

$ man curl

Last but not least, if your results are not pleasing, then you have some adjustments to make on your server or within the code. You may consider using the following tutorials which explain programs and tips to make website(s) load faster in Linux:

  1. Install Nginx with Ngx_Pagespeed (Speed Optimization) on Debian and Ubuntu
  2. Speed Up Nginx Performance with Ngx_Pagespeed on CentOS 7
  3. Learn How to Speed Up Websites Using Nginx and Gzip Module
  4. How to Boost Linux Server Internet Speed with TCP BBR

That’s all! Now you know how to test website response time from the command line. You can ask questions via the feedback form below.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 thoughts on “How to Test Website Loading Speed in Linux Terminal”

  1. This is not bad. But it shows the only basics. I want more like GTmetrix or others. Is it possible to see from the Linux command line?

  2. This is a pretty bad method to meassure the speed of a website cause it does not include javascript or rendering, it just messures the downloadspeed and not how fast the website will be visible to the user!

    • @Spike

      Okay, we will find out more on this and perhaps update this guide with a more appropriate method. Many thanks for sharing this important concern.


Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.