c# - Stopwatch.ElapsedMilliseconds 和 (stopDateTime - startDateTime).TotalMilliseconds 之间的区别

标签 c#

<分区>

我有:

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();

DateTime start  = DateTime.Now;
Thread.Sleep(5000);

stopWatch.Stop();
DateTime stop = DateTime.Now;

//stopWatch.ElapsedMilliseconds approximately equals to (stop - start).TotalMilliseconds

那么这些测量方法有区别吗?

最佳答案

来自 msdn,System.DateTime :

The Now property is frequently used to measure performance. However, because of its low resolution, it is not suitable for use as a benchmarking tool. A better alternative is to use the Stopwatch class.

关于c# - Stopwatch.ElapsedMilliseconds 和 (stopDateTime - startDateTime).TotalMilliseconds 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7784050/

相关文章:

c# - WPF - 将窗口标题绑定(bind)到其他项目公共(public)设置

c# - 如何自动解决 C# 依赖项?

c# - 使用传入的函数对 List<T> 进行排序

c# - 如何根据参数参数运行显示或不显示控制台窗口的 dotnet Core 控制台应用程序?

c# - 如何防止 Selenium C# 中 PageFactory 中的 StaleElementReferenceException?

c# - 如何将二维字符串数组转换为二维 [int, double, bool, ..] 数组?

c# - AppDomain.CurrentDomain.BaseDirectory 在运行测试后发生变化?

C# VSTO 项目从 Excel 2010 更改为 Excel 2007

c# - 泛型,其中 T 是实现接口(interface)的类

c# - 找不到名称为 WCF 的端点元素