我想对我的代码进行一些基本的分析,但是发现C#中的DateTime.Now仅具有大约16 ms的分辨率。必须有更好的时间保存我尚未发现的构造。
最佳答案
这是计时操作的代码示例:
Dim sw As New Stopwatch()
sw.Start()
//Insert Code To Time
sw.Stop()
Dim ms As Long = sw.ElapsedMilliseconds
Console.WriteLine("Total Seconds Elapsed: " & ms / 1000)
编辑:
整洁的是它也可以恢复。
Stopwatch sw = new Stopwatch();
foreach(MyStuff stuff in _listOfMyStuff)
{
sw.Start();
stuff.DoCoolCalculation();
sw.Stop();
}
Console.WriteLine("Total calculation time: {0}", sw.Elapsed);
如果系统上有一个System.Diagnostics.Stopwatch类,它将使用一个高分辨率计数器。
关于.net - .NET中的高分辨率计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/163022/