关于下载速度测试的问题 [英] Question about download speed test

查看:86
本文介绍了关于下载速度测试的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此结果对测试下载速度是否准确?

Would this result be accurate for testing download speed?

const string tempfile = "5MB.zip";
WebClient webClient = new WebClient();
Uri uri = new Ur("http://download.thinkbroadband.com/5MB.zip");
Console.WriteLine("Download test starting please wait....");
Stopwatch sw = Stopwatch.StartNew();
webClient.DownloadFile(uri, tempfile);
sw.Stop();
FileInfo fileInfo = new FileInfo(tempfile);
long speed = fileInfo.Length / sw.Elapsed.Seconds;
Console.WriteLine("Speed: {0} bps ", speed.ToString("N0"));

推荐答案

是的,应该可以.您可能希望在一天中的多个时间和多个URL上运行它,以获得更现实的平均速度.
Yes, that should work. You might want to run it on multiple URLs and at multiple times of the day to get a more realistic average speed.


最好使用DataTime:

Better use DataTime:

System.DateTime before = System.DateTime.Now;
//download all
System.DateTime after = System.DateTime.Now;
System.TimeSpan duration = after - before;
double seconds = duration.TotalSeconds;
double milliseconds = duration.TotalMilliseconds;



注意:您的准确度是相同的,无论使用什么单位,持续时间都将计算为double值.

—SA



Pay attention: your accuracy is the same, no matter what units you use, duration is calculated into double value.

—SA


这篇关于关于下载速度测试的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆