In this article, I will show you how to measure internet speed (download) using C#.
We’ll be using Stopwatch and WebClient to calculate internet speed. For using these classes, add references to the following namespaces first.
To measure the internet speed, I created a stopwatch that starts when we start to download a file or web page and ends when the download completes. Then we’re dividing the total number of bytes downloaded with the time taken to download the file to find the download speed in bytes / second.
Stopwatch watch = new Stopwatch(); //using system.diagnostics
WebClient web = new WebClient();
byte bytes = web.DownloadData("https://www.yoursite.com");
double sec = watch.Elapsed.TotalSeconds;
double speed = bytes.Count() / sec;
Console.WriteLine(speed +" bytes / S");
If you enjoyed this post, let me know by leaving a comment below.