CPU clock frequency and thus QueryPerformanceCounter wrong?

后端 未结 5 1301
灰色年华
灰色年华 2021-02-14 21:09

I am using QueryPerformanceCounter to time some code. I was shocked when the code starting reporting times that were clearly wrong. To convert the results of QPC into \"real\"

5条回答
  •  离开以前
    2021-02-14 21:38

    You can try to use the Stopwatch class from .NET, it could help with your problem since it abstracts from all this low-lever stuff.

    Use the IsHighResolution property to see whether the timer is based on a high-resolution performance counter.

    Note: On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread..::.ProcessorAffinity method.

提交回复
热议问题