Skip to content
Measurements

Measurements

Finding servers

CallReturns
client.FetchUserInfo(ctx)Your IP address, ISP, coordinates, and country, as speedtest.net reports them
client.FetchServers(ctx)The servers near you, or near the location option
client.FetchServerByID(ctx, id)One server by its ID, or ErrServerNotFound
client.CustomServer(url)A server that speedtest.net does not need to list, from its full URL, such as http://speedtest.example.com:8080. Its path is replaced with /speedtest/upload.php
servers.FindServer(ids)The servers with those IDs. With no IDs, or none that match, the server with the lowest latency
servers.FilterCountry(codes...)The servers in those countries, by two-letter code
servers.Available()The servers with a measured latency

Tests

Each test takes a context and a server, and returns its own result. Ending the context ends the test early, which makes it fail.

MethodMeasuresReturns
Ping(ctx, server, opts...)Latency, with the client’s ping modePingStats
Download(ctx, server, opts...)The download rateTransfer
Upload(ctx, server, opts...)The upload rateTransfer
DownloadMulti(ctx, main, pool, opts...)The download rate across several servers at once. The main server gets the main share of the connections, and the other available servers in the pool share the restTransfer
UploadMulti(ctx, main, pool, opts...)The upload rate across several servers, shared like DownloadMultiTransfer
PacketLoss(ctx, server)Packet loss, until the context ends. See Packet LossPacketLossStats

Options for one test

OptionForSetsDefault
WithPingCount(n)PingThe number of round trips10
WithPingInterval(d)PingThe wait after each round trip200 milliseconds
WithLatencyCallback(fn)PingA function that receives each round trip as it is measuredNone
WithProgressCallback(fn)TransfersA function that receives the rate estimate, the elapsed time, and the estimated time left while the test runsNone

Results

PingStats:

FieldHolds
LatencyThe mean round trip
JitterThe standard deviation of the round trips
Min, MaxThe shortest and longest round trips
LatenciesEvery round trip, in the order they were sent
DurationHow long the measurement took

Transfer:

FieldHolds
RateBytes per second over the test’s capture window, or -1 when no data was counted and more than a tenth of the requests failed
BytesThe bytes downloaded, or the upload bytes the servers confirmed
SentThe upload bytes sent, confirmed or not. 0 for downloads
WindowThe capture window the rate is measured over
DurationHow long the test took
Requests, FailuresHow many requests the test sent, and how many failed
ConnectionsThe bytes, requests, failures, and active time of each connection

A ByteRate such as Transfer.Rate prints in Mbps. Format chooses another unit, such as rate.Format(speedtest.UnitTypeBinaryBits), and Mbps and Gbps return numbers.

JSON

A speedtest.Result collects one server’s results. speedtest.JSON and speedtest.JSONL write results in the CLI’s JSON format, described in Reading the Results:

report, err := speedtest.JSON(user, []speedtest.Result{{
	Server:   server,
	Ping:     &ping,
	Download: &download,
	Upload:   &upload,
}})

Errors

Check errors with errors.Is and errors.As:

ErrorMeans
ErrInvalidOptionNew rejected a client option, or Ping rejected a ping option
ErrServerNotFoundNo server is available, or none has the requested ID
*StatusError, wrapping ErrUnexpectedStatusA server answered with an HTTP status outside 2xx
ErrUnsupportedA server does not serve the packet loss protocol
context.Canceled, context.DeadlineExceededThe test’s context ended before it finished