How to use QueryPerformanceCounter?

后端 未结 4 1776
难免孤独
难免孤独 2020-11-22 08:36

I recently decided that I needed to change from using milliseconds to microseconds for my Timer class, and after some research I\'ve decided that QueryPerformanceCounter is

4条回答
  •  轮回少年
    2020-11-22 09:17

    I would extend this question with a NDIS driver example on getting time. As one knows, KeQuerySystemTime (mimicked under NdisGetCurrentSystemTime) has a low resolution above milliseconds, and there are some processes like network packets or other IRPs which may need a better timestamp;

    The example is just as simple:

    LONG_INTEGER data, frequency;
    LONGLONG diff;
    data = KeQueryPerformanceCounter((LARGE_INTEGER *)&frequency)
    diff = data.QuadPart / (Frequency.QuadPart/$divisor)
    

    where divisor is 10^3, or 10^6 depending on required resolution.

提交回复
热议问题