How to Use the Command 'speedtest' (with Examples)
The speedtest
command is the official command-line interface for testing internet bandwidth using Speedtest.net, a widely recognized tool for measuring your internet connection’s speed. By executing this command, users can evaluate download and upload speeds, as well as latency. This command offers different options to customize the output, such as specifying units, output formats, and precision levels. Speedtest can be particularly useful for networking professionals or users who need to diagnose network performance without accessing a web browser.
Use Case 1: Run a Basic Speed Test
Code:
speedtest
Motivation: Running a basic speed test allows users to quickly understand the current performance of their internet connection. It can be used as a diagnostic tool to check whether your internet service provider is delivering the speeds promised in your internet plan or if there are issues that need to be addressed.
Explanation: The speedtest
command, when run without any additional arguments, performs a standard network speed test. This test measures your download speed, upload speed, and ping (latency) in a straightforward and convenient manner. It uses the nearest available server to provide the most accurate results.
Example Output:
Speedtest by Ookla
Server: Local ISP - CityName (city code)
Ping: 22.134 ms
Download: 107.24 Mbps
Upload: 39.67 Mbps
Use Case 2: Run a Speed Test with Specified Units
Code:
speedtest --unit=auto-decimal-bits
Motivation: Internet speeds and data are measured in various units such as bits, bytes, etc. This option aligns the output to a unit of measurement that users are most comfortable with, enhancing the interpretability of the results.
Explanation: The --unit
argument allows the user to choose among different unit formats: auto-decimal-bits
, auto-decimal-bytes
, auto-binary-bits
, and auto-binary-bytes
. By choosing auto-decimal-bits
, the results will automatically be formatted using decimal bits, which is a common unit and offers a straightforward way to interpret the speed results.
Example Output:
Speedtest by Ookla
Server: Local ISP - CityName (city code)
Ping: 22.134 ms
Download: 107.24 Mbit/s
Upload: 39.67 Mbit/s
Use Case 3: Run a Speed Test with Specified Output Format
Code:
speedtest --format=json
Motivation: Specifying an output format is essential for users who need the speedtest results in a format that can be easily processed by applications, scripts, or tools. JSON, CSV, and TSV formats are often preferred for further data analysis.
Explanation: The --format
argument is used to define how the output of the speedtest will be displayed. In this case, json
specifies that the results will be returned in JSON format, making it easier to import into data analysis software or scripts for further processing.
Example Output:
{
"type": "result",
"timestamp": "2023-03-02T14:22:45Z",
"ping": {
"jitter": 0.305,
"latency": 22.534
},
"download": {
"bandwidth": 13486724,
"bytes": 161024080,
"elapsed": 10202
},
"upload": {
"bandwidth": 8325876,
"bytes": 85125432,
"elapsed": 10223
}
}
Use Case 4: Run a Speed Test with Specified Decimal Precision
Code:
speedtest --precision=4
Motivation: Controlling the precision of the result is crucial when detailed analysis or reporting is required. For scenarios needing high accuracy, like in network performance studies, having a higher number of decimal places can be important for precise calculations.
Explanation: By using the --precision
argument followed by a number (in this case, 4), the user instructs the command to use four decimal places for speed results. This can offer greater accuracy to those needing more detailed results, which could be essential for certain technical evaluations.
Example Output:
Speedtest by Ookla
Server: Local ISP - CityName (city code)
Ping: 22.1342 ms
Download: 107.2437 Mbps
Upload: 39.6735 Mbps
Use Case 5: Run a Speed Test with Progress Display
Code:
speedtest --progress=yes
Motivation: Observing the progress of a test can be beneficial for understanding how stable or variable the connection is during the evaluation period. This real-time feedback can help diagnose issues that may not be evident from the end results alone.
Explanation: The --progress
argument with value yes
enables the user to see the test’s progress in real-time. This feature, available only in human-readable
and json
output formats, will display a dynamic indication of the ongoing speedtest, helping users monitor changes or fluctuations during the testing process.
Example Output:
Testing in progress...
Ping: [###--------------------] 25%
Download: [#########-----------] 57%
Upload: [############----------] 65%
Use Case 6: List Available Speedtest Servers Sorted by Distance
Code:
speedtest --servers
Motivation: For those looking to run a speed test with a specific server or interested in understanding which test servers are near their location, the server list provides this information sorted by proximity. This can assist in selecting the most appropriate server for more accurate results.
Explanation: The --servers
argument prompts the command to list all available test servers, sorted by their distance from the user’s current location. This feature is useful for users who might want a test server that closely matches their geographical area or ensures optimal results.
Example Output:
Server ID: 12345) ISP: Local ISP - CityName (distance: 5.42 km)
Server ID: 67890) ISP: Regional ISP - AnotherCity (distance: 50.21 km)
Server ID: 24680) ISP: International ISP - FurtherCity (distance: 101.78 km)
Use Case 7: Run a Speed Test to a Specific Server
Code:
speedtest --server-id=12345
Motivation: Choosing a specific server to perform the speed test can help pinpoint issues related to specific geographic locations or server configurations. This can be useful for those working in network performance at an enterprise level or for QA testing.
Explanation: The --server-id
argument specifies which test server to use, with 12345
being the server’s unique identifier. Users obtain the server ID from the --servers
list. Testing with a chosen server allows for targeted evaluation, useful when measuring inter-regional network performance or when verifying connection to company-specific infrastructure.
Example Output:
Speedtest by Ookla
Server: CustomISP - CustomCity (city code)
Ping: 15.674 ms
Download: 115.36 Mbps
Upload: 41.78 Mbps
Conclusion:
The speedtest
command-line tool provides a flexible and powerful way to measure internet connection performance. By leveraging various options like unit specification, format output, precision control, server selection, and real-time progress updates, users can tailor the tool’s output to meet specific needs. From quick, general assessments to detailed, customized tests, the speedtest command is an invaluable utility for IT professionals, network administrators, and even everyday users seeking insights into their internet performance.