• Stars
    star
    542
  • Rank 81,982 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CLI and Go API to Test Internet Speed using speedtest.net

speedtest-go

Command Line Interface and pure Go API to Test Internet Speed using speedtest.net.

You can speedtest 2x faster than speedtest.net with almost the same result. See the experimental results. Inspired by sivel/speedtest-cli

CLI

Installation

macOS (homebrew)

$ brew tap showwin/speedtest
$ brew install speedtest

### How to Update ###
$ brew update
$ brew upgrade speedtest

Nix (package manager)

# Enter the latest speedtest-go environment
$ nix-shell -p speedtest-go

Other Platforms (Linux, Windows, etc.)

Please download the compatible package from Releases. If there are no compatible packages you want, please let me know on Issue Tracker.

Usage

$ speedtest --help
usage: speedtest-go [<flags>]

Flags:
      --help                   Show context-sensitive help (also try --help-long and --help-man).
  -l, --list                   Show available speedtest.net servers.
  -s, --server=SERVER ...      Select server id to speedtest.
      --custom-url=CUSTOM-URL  Specify the url of the server instead of getting a list from speedtest.net.
      --saving-mode            Test with few resources, though low accuracy (especially > 30Mbps).
      --json                   Output results in json format.
      --location=LOCATION      Change the location with a precise coordinate.
      --city=CITY              Change the location with a predefined city label.
      --city-list              List all predefined city labels.
      --proxy=PROXY            Set a proxy(http[s] or socks) for the speedtest.
                               eg: --proxy=socks://10.20.0.101:7890
                               eg: --proxy=http://10.20.0.101:7890
      --source=SOURCE          Bind a source interface for the speedtest.
                               eg: --source=10.20.0.101
  -m  --multi                  Enable multi-server mode.
  -t  --thread=THREAD          Set the number of concurrent connections.
      --search=SEARCH          Fuzzy search servers by a keyword.
      --no-download            Disable download test.
      --no-upload              Disable upload test.
      --force-http-ping        Force ping using http.
  -d  --debug                  Enable debug mode.
      --version                Show application version.

Test Internet Speed

Simply use speedtest command. The closest server is selected by default. Use the -m flag to enable multi-measurement mode (recommended)

$ speedtest

    speedtest-go v1.6.5 @showwin

โœ“ ISP: 124.27.199.165 (Fujitsu) [34.9769, 138.3831]
โœ“ Found 20 Public Servers

โœ“ Test Server: [6691] 9.03km Shizuoka (Japan) by sudosan
โœ“ Latency: 24.15396ms Jitter: 777.465ยตs Min: 22.8926ms Max: 25.5387ms
โœ“ Download: 73.30Mbps (used: 101.48MB)
โœ“ Upload: 35.26Mbps (used: 47.33MB)

Test with Other Servers

If you want to select other servers to test, you can see the available server list.

$ speedtest --list
Testing From IP: 124.27.199.165 (Fujitsu) [34.9769, 138.3831]
[6691]     9.03km   32.3365ms  Shizuoka (Japan) by sudosan
[6087]   120.55km   51.7453ms  Fussa-shi (Japan) by Allied Telesis Capital Corporation
[6508]   125.44km   54.6683ms  Yokohama (Japan) by at2wn
[6424]   148.23km   61.4724ms  Tokyo (Japan) by Cordeos Corp.
...

and select them by id.

$ speedtest --server 6691 --server 6087

    speedtest-go v1.6.5 @showwin

โœ“ ISP: 124.27.199.165 (Fujitsu) [34.9769, 138.3831]
โœ“ Found 20 Public Servers

โœ“ Test Server: [6691] 9.03km Shizuoka (Japan) by sudosan
โœ“ Latency: 21.424ms Jitter: 1.644ms Min: 19.142ms Max: 23.926ms
โœ“ Download: 65.82Mbps (used: 75.48MB)
โœ“ Upload: 27.00Mbps (used: 36.33MB)

โœ“ Test Server: [6087] 120.55km Fussa-shi (Japan) by Allied Telesis Capital Corporation
โœ“ Latency: 38.694699ms Jitter: 2.724ms Min: 36.443ms Max: 39.953ms
โœ“ Download: 72.24Mbps (used: 83.72MB)
โœ“ Upload: 29.56Mbps (used: 47.64MB)

Download Avg: 69.03 Mbit/s
Upload Avg: 28.28 Mbit/s

Test with a virtual location

With --city or --location option, the closest servers of the location will be picked. You can measure the speed between your location and the target location.

$ speedtest --city-list
Available city labels (case insensitive):
 CC             CityLabel       Location
(za)                capetown    [-33.9391993, 18.4316716]
(pl)                  warsaw    [52.2396659, 21.0129345]
(sg)                  yishun    [1.4230218, 103.8404728]
...

$ speedtest --city=capetown
$ speedtest --location=60,-110

Memory Saving Mode

With --saving-mode option, it can be executed even in an insufficient memory environment like IoT devices. The memory usage can be reduced to 1/10, about 10MB of memory is used.

However, please be careful that the accuracy is particularly low, especially in an environment of 30 Mbps or higher. To get more accurate results, run multiple times and average.

For more details, please see saving mode experimental result.

โš ๏ธThis feature has been deprecated > v1.4.0, because speedtest-go can always run with less than 10MBytes of memory now. Even so, --saving-mode is still a good way to reduce computation.

Go API

go get github.com/showwin/speedtest-go

API Usage

The code below finds the closest available speedtest server and tests the latency, download, and upload speeds.

package main

import (
	"fmt"
	"github.com/showwin/speedtest-go/speedtest"
)

func main() {
	var speedtestClient = speedtest.New()
	
	// Use a proxy for the speedtest. eg: socks://127.0.0.1:7890
	// speedtest.WithUserConfig(&speedtest.UserConfig{Proxy: "socks://127.0.0.1:7890"})(speedtestClient)
	
	// Select a network card as the data interface.
	// speedtest.WithUserConfig(&speedtest.UserConfig{Source: "192.168.1.101"})(speedtestClient)
	
	// Get user's network information
	// user, _ := speedtestClient.FetchUserInfo()
	
	// Get a list of servers near a specified location
	// user.SetLocationByCity("Tokyo")
	// user.SetLocation("Osaka", 34.6952, 135.5006)
    
	// Search server using serverID.
	// eg: fetch server with ID 28910.
	// speedtest.ErrServerNotFound will be returned if the server cannot be found.
	// server, err := speedtest.FetchServerByID("28910")
	
	serverList, _ := speedtestClient.FetchServers()
	targets, _ := serverList.FindServer([]int{})

	for _, s := range targets {
		// Please make sure your host can access this test server,
		// otherwise you will get an error.
		// It is recommended to replace a server at this time
		s.PingTest(nil)
		s.DownloadTest()
		s.UploadTest()
		fmt.Printf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed)
	}
}

Summary of Experimental Results

Speedtest-go is a great tool because of the following 4 reasons:

The following data is summarized. If you got interested, please see more details.

Download (Mbps)

distance = distance to testing server

  • 0 - 1000(km) โ‰’ domestic
  • 1000 - 8000(km) โ‰’ same region
  • 8000 - 20000(km) โ‰’ really far!
  • 20000km is half of the circumference of our planet.
distance (km) speedtest.net speedtest-go speedtest-cli
0 - 1000 92.12 91.21 70.27
1000 - 8000 66.45 65.51 56.56
8000 - 20000 11.84 9.43 11.87

Upload (Mbps)

distance (km) speedtest.net speedtest-go speedtest-cli
0 - 1000 65.56 47.58 36.16
1000 - 8000 58.02 54.74 26.78
8000 - 20000 5.20 8.32 2.58

Testing Time (sec)

distance (km) speedtest.net speedtest-go speedtest-cli
0 - 1000 45.03 22.84 24.46
1000 - 8000 44.89 24.45 28.52
8000 - 20000 49.64 34.08 41.26

Contributors

See Contributors, PRs are welcome!

Issues

You can find or report issues in the Issue Tracker.

LICENSE

MIT

More Repositories

1

ISHOCON1

iikanji na showwin contest 1st (like ISUCON)
Go
57
star
2

ISHOCON2

iikanjina showwin contest 2nd (like ISUCON)
Ruby
38
star
3

kintai-paccho

Slackใ‹ใ‚‰ๅ‹คๆ€ ๅ…ฅๅŠ›ใ™ใ‚‹Slack Botใ ใฑใฃใกใ‚‡
Python
13
star
4

FeVPN

VPN Auto Connection App for OS X written in AppleScript
8
star
5

hakari

Stress Test Tool for Web Application
Go
5
star
6

Gizix

Private Audio Call App like Skype which can take dictation from your conversation.
JavaScript
4
star
7

myquerydump

mysqldump with any SELECT query.
Go
3
star
8

make-me-showwin

create showwin icon which face is yours.
Python
2
star
9

QIDB

Personal Business
HTML
2
star
10

Tiny-C

Tiny-C compiler written in C
C
2
star
11

Automatic-Deploy-Tool-for-Rails

Deploy Tool for Rails app using GitHub Webhook
Ruby
2
star
12

YamashitaHelper

help yamashita-san to scrape website
Ruby
1
star
13

seisindo

Shell
1
star
14

sudoku

ๆ•ฐ็‹ฌใ‚’่งฃใใ‚นใ‚ฏใƒชใƒ—ใƒˆ
Ruby
1
star
15

ResortWork

ใƒชใ‚พใƒผใƒˆๅœฐใงใƒชใƒขใƒผใƒˆใƒฏใƒผใ‚ฏใ™ใ‚‹ใž๏ผ
1
star
16

ISHOCON3

iikanji na showwin contest 3rd (like ISUCON)
Python
1
star
17

rack-error_to_slack

rack middleware to post error messages to slack
Ruby
1
star
18

glassfrog-private-project-extension

Chrome Extension to create private project in glassfrog.com by default.
JavaScript
1
star
19

punch-clock-by-face

Punch a clock by your face / ้ก”่ช่จผใงๅ‹คๆ€ ๆ‰“ๅˆปใ™ใ‚‹ใž
Python
1
star
20

DisneyWT

Web Service to see Disneyland Waiting Time. Support 4 Disneylands in Asia.
Ruby
1
star