NetPace.Core
Network speed test library including server discovery, latency measurement, download and upload speed testing.
NetPace is pre-1.0. Any release may change or remove command-line options, output formats or NetPace.Core library members, without a deprecation period. Backward compatibility will be maintained from 1.0.0 onwards.
Fan of NetPace? Consider giving the repo a star ⭐ - it helps others find it too.
Quick Start
using NetPace.Core;
using NetPace.Core.Clients.Ookla;
var speedTester = new OoklaSpeedtest() as ISpeedTestService;
var servers = await speedTester.GetServersAsync();
var fastest = await speedTester.GetFastestServerByLatencyAsync(servers);
var downloadResult = await speedTester.GetDownloadSpeedAsync(fastest.Server);
var uploadResult = await speedTester.GetUploadSpeedAsync(fastest.Server);
Console.WriteLine($"{fastest.Server.Sponsor} ({fastest.LatencyMilliseconds} ms)");
Console.WriteLine($"Download: {downloadResult.GetSpeedString(SpeedUnit.BitsPerSecond, SpeedUnitSystem.SI)}");
Console.WriteLine($"Upload: {uploadResult.GetSpeedString(SpeedUnit.BitsPerSecond, SpeedUnitSystem.SI)}");
The example above uses the OoklaSpeedtest implementation which uses Ookla Speedtest servers under the hood. Ookla and Speedtest are trademarks of Ookla, LLC; this project is not affiliated with or endorsed by Ookla.
LibreSpeedtest is the other implementation, for a LibreSpeed server you host yourself. It speaks the same ISpeedTestService and reports the same figures, with the server named by the address LibreSpeed is installed at. It discovers no servers, so GetServersAsync throws NotSupportedException; screening a list you supply yourself works as it does for Ookla.
using NetPace.Core.Clients.LibreSpeed;
var speedTester = new LibreSpeedtest() as ISpeedTestService;
var latency = await speedTester.GetServerLatencyAsync("http://pi.local:8080/");
var downloadResult = await speedTester.GetDownloadSpeedAsync(latency.Server);
See the full example on GitHub.
API Overview
ISpeedTestService is the primary interface you will interact with.
public interface ISpeedTestService
{
public Task<IServer[]> GetServersAsync(CancellationToken cancellationToken = default);
public Task<LatencyTestResult> GetServerLatencyAsync(IServer server, CancellationToken cancellationToken = default);
public Task<LatencyTestResult> GetServerLatencyAsync(IServer server, IProgress<LatencyTestProgress> progress, CancellationToken cancellationToken = default);
public Task<LatencyTestResult> GetServerLatencyAsync(IServer server, IProgress<LatencyTestProgress>? progress, IProgress<RequestDiagnostic>? diagnostics, CancellationToken cancellationToken = default, CancellationToken stopAndReportToken = default);
public Task<LatencyTestResult> GetServerLatencyAsync(string serverUrl, CancellationToken cancellationToken = default);
public Task<LatencyTestResult> GetServerLatencyAsync(string serverUrl, IProgress<LatencyTestProgress> progress, CancellationToken cancellationToken = default);
public Task<LatencyTestResult> GetServerLatencyAsync(string serverUrl, IProgress<LatencyTestProgress>? progress, IProgress<RequestDiagnostic>? diagnostics, CancellationToken cancellationToken = default, CancellationToken stopAndReportToken = default);
public Task<LatencyTestResult> GetFastestServerByLatencyAsync(IServer[] servers, CancellationToken cancellationToken = default);
public Task<LatencyTestResult> GetFastestServerByLatencyAsync(IServer[] servers, IProgress<SpeedTestProgress> progress, CancellationToken cancellationToken = default);
public Task<LatencyTestResult> GetFastestServerByLatencyAsync(IServer[] servers, IProgress<SpeedTestProgress>? progress, IProgress<RequestDiagnostic>? diagnostics, CancellationToken cancellationToken = default);
public Task<SpeedTestResult> GetDownloadSpeedAsync(IServer server, CancellationToken cancellationToken = default);
public Task<SpeedTestResult> GetDownloadSpeedAsync(IServer server, IProgress<SpeedTestProgress> progress, CancellationToken cancellationToken = default);
public Task<SpeedTestResult> GetDownloadSpeedAsync(IServer server, IProgress<SpeedTestProgress>? progress, IProgress<RequestDiagnostic>? diagnostics, CancellationToken cancellationToken = default, CancellationToken stopAndReportToken = default);
public Task<SpeedTestResult> GetUploadSpeedAsync(IServer server, CancellationToken cancellationToken = default);
public Task<SpeedTestResult> GetUploadSpeedAsync(IServer server, IProgress<SpeedTestProgress> progress, CancellationToken cancellationToken = default);
public Task<SpeedTestResult> GetUploadSpeedAsync(IServer server, IProgress<SpeedTestProgress>? progress, IProgress<RequestDiagnostic>? diagnostics, CancellationToken cancellationToken = default, CancellationToken stopAndReportToken = default);
}
See ISpeedTestService on GitHub.
Testing Your Code
NetPace.Core includes test doubles for the library's interfaces so you can test your code without making real network calls. They are a supported part of the library: each double's documented behaviour is covered by its own tests, so a release cannot change one of these figures without a test failing first.
SpeedTestStub - Simple stub returning fixed values with configurable delays
SpeedTestMock - Fully configurable mock with injectable delegate functions
VariableSpeedTester - Returns different speeds on each call (simulates variable network conditions)
FaultySpeedTester - Simulates network failures and timeouts (for testing error handling)
DelayProviderStub - Stands in for IDelayProvider, recording the pauses your code asked for instead of waiting them out
See the implementations in NetPace.Core.Clients.Testing and their usage throughout the solution.