speedtest

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 15 Imported by: 2

README

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.

This fork allows abstracts the implementation of the speed test to a package so it can be used by other go programs.

Inspired by sivel/speedtest-cli

API Installation

go get github.com/cbergoon/speedtest-go

CLI Installation

go install github.com/cbergoon/speedtest-go

CLI Usage

$ speedtest --help
usage: download [<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
  -t, --timeout=TIMEOUT  Define timeout seconds. Default: 10 sec
      --version          Show application version.
Select Closest Server by Default
$ speedtest
Testing From IP: 124.27.199.165 (Fujitsu) [34.9769, 138.3831]

Target Server: [6691]     9.03km Shizuoka (Japan) by sudosan
latency: 39.436061ms
Download Test: ................
Upload Test: ................

Download: 73.30 Mbit/s
Upload: 35.26 Mbit/s
Show Available Servers
$ speedtest --list
Testing From IP: 124.27.199.165 (Fujitsu) [34.9769, 138.3831]
[6691]     9.03km Shizuoka (Japan) by sudosan
[6087]   120.55km Fussa-shi (Japan) by Allied Telesis Capital Corporation
[6508]   125.44km Yokohama (Japan) by at2wn
[6424]   148.23km Tokyo (Japan) by Cordeos Corp.
[6492]   153.06km Sumida (Japan) by denpa893
[7139]   192.63km Tsukuba (Japan) by SoftEther Corporation
[6368]   194.83km Maibara (Japan) by gatolabo
[6463]   220.39km Kusatsu (Japan) by j416dy
[6766]   232.54km Nomi (Japan) by JAIST(ino-lab)
[6476]   265.10km Osaka (Japan) by rxy (individual)
[6477]   268.94km Sakai (Japan) by satoweb
...
Select Multiple Servers by Server ID
$ speedtest --server 6691 --server 6087
Testing From IP: 124.27.199.165 (Fujitsu) [34.9769, 138.3831]

Target Server: [6691]     9.03km Shizuoka (Japan) by sudosan
Latency: 23.612861ms
Download Test: ................
Upload Test: ........

Target Server: [6087]   120.55km Fussa-shi (Japan) by Allied Telesis Capital Corporation
Latency: 38.694699ms
Download Test: ................
Upload Test: ................

[6691] Download: 65.82 Mbit/s, Upload: 27.00 Mbit/s
[6087] Download: 72.24 Mbit/s, Upload: 29.56 Mbit/s
Download Avg: 69.03 Mbit/s
Upload Avg: 28.28 Mbit/s

Summary of Experimental Results

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

Following data is summarized.

Download (Mbps)

distance = distance to testing server

  • 0 - 1000(km) ≒ domestic
  • 1000 - 8000(km) ≒ same region
  • 8000 - 20000(km) ≒ really far!
  • 20000km is the 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

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByDistance

type ByDistance struct {
	Servers
}

ByDistance for sorting servers.

func (ByDistance) Less

func (b ByDistance) Less(i, j int) bool

Less compares the distance. For sorting servers.

type Server

type Server struct {
	URL      string `xml:"url,attr"`
	Lat      string `xml:"lat,attr"`
	Lon      string `xml:"lon,attr"`
	Name     string `xml:"name,attr"`
	Country  string `xml:"country,attr"`
	Sponsor  string `xml:"sponsor,attr"`
	ID       string `xml:"id,attr"`
	URL2     string `xml:"url2,attr"`
	Host     string `xml:"host,attr"`
	Distance float64
	Latency  time.Duration
	DLSpeed  float64
	ULSpeed  float64
}

Server information

func (Server) CheckResultValid added in v1.1.0

func (s Server) CheckResultValid() bool

CheckResultValid checks that results are logical given UL and DL speeds

func (*Server) DownloadTest

func (s *Server) DownloadTest() error

DownloadTest executes the test to measure download speed

func (*Server) PingTest added in v1.1.0

func (s *Server) PingTest() error

PingTest executes test to measure latency

func (*Server) String added in v1.1.0

func (s *Server) String() string

String representation of Server

func (*Server) UploadTest

func (s *Server) UploadTest() error

UploadTest executes the test to measure upload speed

type ServerList added in v1.0.2

type ServerList struct {
	Servers []*Server `xml:"servers>server"`
}

ServerList list of Server

func FetchServerList

func FetchServerList(user *User) (ServerList, error)

FetchServerList retrieves a list of available servers

func (*ServerList) FindServer added in v1.0.2

func (l *ServerList) FindServer(serverID []int) (Servers, error)

FindServer finds server by serverID

func (*ServerList) String added in v1.1.0

func (l *ServerList) String() string

String representation of ServerList

type Servers

type Servers []*Server

Servers for sorting servers.

func (Servers) Len

func (svrs Servers) Len() int

Len finds length of servers. For sorting servers.

func (Servers) Swap

func (svrs Servers) Swap(i, j int)

Swap swaps i-th and j-th. For sorting servers.

type User

type User struct {
	IP  string `xml:"ip,attr"`
	Lat string `xml:"lat,attr"`
	Lon string `xml:"lon,attr"`
	Isp string `xml:"isp,attr"`
}

User represents information determined about the caller by speedtest.net

func FetchUserInfo

func FetchUserInfo() (*User, error)

FetchUserInfo returns information about caller determined by speedtest.net

func (*User) String added in v1.1.0

func (u *User) String() string

String representation of User

type Users

type Users struct {
	Users []User `xml:"client"`
}

Users for decode xml

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL