Test Website Loading Speed in Linux Terminal

Test Website Loading Speed in Linux Terminal

Testing the loading speed of a website is essential for understanding its performance and user experience. Website loading speed is crucial for SEO, user engagement, and overall success. Fortunately, Linux provides several tools to test website speed directly from the terminal. These tools are versatile, efficient, and offer valuable insights into how quickly your website loads.

This guide will walk you through the process of testing the loading speed of a specific website using various Linux terminal tools. We’ll explore commands and tools like cURL, wget, time, and more specialized tools such as httperf and webscreenshot.

1. Why Website Loading Speed Matters

Before diving into the tools, it’s important to understand why loading speed is important. Fast-loading websites rank better in search engines, offer a better user experience, and reduce bounce rates. Users expect websites to load quickly, and even a delay of a few seconds can lead to frustration and loss of traffic. Testing and optimizing website speed is crucial for maintaining a competitive edge online.

2. Using cURL for Basic Speed Testing

cURL is a command-line tool that transfers data from or to a server using various protocols. It’s widely used for testing the performance of websites.

Basic cURL Command for Website Speed

To test the loading speed of a website, you can use the following cURL command:

curl -o /dev/null -s -w 'Total Time: %{time_total}n' https://example.com

Explanation of the Command:

  • -o /dev/null: This option discards the output of the cURL command.
  • -s: This option runs the command in silent mode, suppressing progress information.
  • -w 'Total Time: %{time_total}n': This option tells cURL to output the total time it took to load the webpage.

This command will give you the total loading time of the specified website in seconds.

Interpreting the Results

The output will look something like this:

Total Time: 1.234

This indicates that the website took 1.234 seconds to load. You can run this command multiple times to get an average loading time.

3. Testing with wget for Detailed Analysis

wget is another powerful command-line tool for retrieving files from the web. It can be used to test the loading speed of websites in a way similar to cURL, but with more detailed output.

Basic wget Command for Speed Testing

Use the following wget command to test website loading speed:

wget -p -o log.txt https://example.com

Explanation of the Command:

  • -p: This option downloads all necessary files to view the page offline.
  • -o log.txt: This option logs the output to a file named log.txt.

Analyzing the Output

After running the command, open the log.txt file to find detailed information about the loading time. Look for the line starting with “Downloaded:” to find the total time taken.

Example Output:

Downloaded: 1 files, 100K in 0.123s (813 KB/s)

This output shows that the website and its resources were downloaded in 0.123 seconds.

4. Measuring Load Time with the time Command

The time command in Linux is useful for measuring the execution time of a command. By combining time with cURL or wget, you can accurately measure the loading time of a website.

Using time with cURL

Here’s how you can use the time command with cURL:

time curl -o /dev/null -s https://example.com

Using time with wget

Similarly, you can use the time command with wget:

time wget -q -p https://example.com

Understanding the Output

The output will look something like this:

real    0m1.234s
user    0m0.456s
sys     0m0.123s

The real value indicates the actual time it took for the command to run, which reflects the website’s loading time.

5. Advanced Testing with httperf

httperf is a tool specifically designed for testing the performance of web servers. It allows you to simulate multiple requests and analyze how the server handles them. This tool is more advanced than cURL and wget, providing deeper insights.

Installing httperf

You can install httperf on most Linux distributions using the package manager:

sudo apt-get install httperf

Basic httperf Command for Speed Testing

Once installed, you can use httperf to test the loading speed of a website:

httperf --server=example.com --num-conns=10 --rate=1

Explanation of the Command:

  • --server=example.com: Specifies the website to test.
  • --num-conns=10: Sends 10 requests to the server.
  • --rate=1: Sends 1 request per second.

Analyzing the Output

The output will provide a detailed analysis of the requests, including connection time, response time, and any errors encountered. Look for the “Total” section to find the average response time.

Example Output:

Reply time [ms]: min 123.4, avg 234.5, max 345.6

This output shows the minimum, average, and maximum response times in milliseconds.

6. Visual Testing with webscreenshot

While the previous tools provide numerical data, webscreenshot allows you to visualize how the website loads over time. This tool takes screenshots of websites at different stages of loading, providing a visual representation of loading speed.

Installing webscreenshot

First, install webscreenshot by cloning the repository and installing the dependencies:

git clone https://github.com/defparam/webscreenshot.git
cd webscreenshot
pip install -r requirements.txt

Basic Command for Capturing Screenshots

After installing, use the following command to capture screenshots:

python webscreenshot.py https://example.com

Explanation of the Command:

  • python webscreenshot.py: Runs the webscreenshot script.
  • https://example.com: Specifies the website to capture.

Viewing the Results

The screenshots will be saved in the current directory. You can view them to see how the website loads over time, identifying any elements that take longer to load.

7. Automating Tests with Shell Scripts

If you need to test the loading speed of a website frequently, you can automate the process using shell scripts. This allows you to run the tests periodically and log the results for analysis.

Basic Shell Script for Testing with cURL

Here’s a simple shell script to test website speed with cURL and log the results:

#!/bin/bash

URL="https://example.com"
LOGFILE="speed_log.txt"

while true; do
    TIME=$(curl -o /dev/null -s -w '%{time_total}' $URL)
    echo "$(date): $TIME seconds" >> $LOGFILE
    sleep 60
done

Explanation of the Script:

  • URL="https://example.com": Specifies the website to test.
  • LOGFILE="speed_log.txt": Specifies the file to log the results.
  • while true; do: Starts an infinite loop.
  • TIME=$(curl -o /dev/null -s -w '%{time_total}' $URL): Runs the cURL command and stores the result.
  • echo "$(date): $TIME seconds" >> $LOGFILE: Logs the result with a timestamp.
  • sleep 60: Waits for 60 seconds before repeating the test.

Running the Script

Save the script as test_speed.sh, make it executable, and run it:

chmod +x test_speed.sh
./test_speed.sh

This script will continuously test the website loading speed every minute and log the results.

8. Conclusion

Testing the loading speed of a website is crucial for ensuring a smooth user experience. Linux provides powerful tools like cURL, wget, time, httperf, and webscreenshot for testing and analyzing website performance.

By using these tools, you can identify slow-loading elements, optimize performance, and ultimately improve user satisfaction. Whether you are a developer, sysadmin, or just a curious user, understanding how to test website speed from the Linux terminal is an invaluable skill.

Start with simple tools like cURL and wget, then explore more advanced options like httperf for in-depth analysis. With practice, you’ll be able to optimize websites for faster loading times, ensuring they meet the high expectations of today’s users.

Fedya Serafiev

Fedya Serafiev

Fedya Serafiev owns the website linuxcodelab.eu. He finds satisfaction in helping people solve even the most complex technical problems. His current goal is to write easy-to-follow articles so that such problems do not arise at all.

Thank you for reading the article! If you found the information useful, you can donate using the buttons below: