Is it possible to read the internal CPU tick counter from C#?

前端 未结 3 1581
梦毁少年i
梦毁少年i 2021-01-14 09:50

I have a multithreaded C# program where I need to log how many ticks each thread spends in a specific spin wait lock.

I know there are methods for doing that from C

3条回答
  •  清歌不尽
    2021-01-14 10:08

    You could use QueryPerformanceCounter and QueryPerformenceFrequency.
    You can find an example here.

    System.Diagnostics.Stopwatch should be a high-perfomance counter.
    However, it it not present in Compact Framework but the above solution fixes that problem.

提交回复
热议问题