High-Performance Timer vs StopWatch

前端 未结 3 953
清酒与你
清酒与你 2020-12-15 16:02

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

3条回答
  •  情书的邮戳
    2020-12-15 16:57

    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.

提交回复
热议问题