High-Performance Timer vs StopWatch

对着背影说爱祢 提交于 2019-12-18 03:04:09

问题


Does anyone know if the HiPerfTimer or the StopWatch class is better for benchmarking, and why?


回答1:


Stopwatch is based on High resolution timer (where available), you can check that with IsHighResolution




回答2:


They are the same when it comes to high resolution timing.

Both use this:

[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(out long PerformanceCount);

and this:

[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(out long Frequency);

to do the underlying timing. (You can verify this with Reflector.NET). I'd use StopWatch because it's part of the framework already (no need to link another dll) and it had better features than HiPerfTimer.




回答3:


StopWatch- it also works on systems that don't support a high resolution performance counter and you don't need any external libraries to use it.

The other one throws an Win32Exception if there is no support for a high resolution counter.



来源:https://stackoverflow.com/questions/1485839/high-performance-timer-vs-stopwatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!