开发者

C++ QueryPerformanceCounter and QueryPerformanceFrequency

I have been attempting to create a timer for my game and 开发者_开发百科I heard about QueryPerformanceCounter and QueryPerformanceFrequency. Could someone please explain how these can be used to calculate time/fps/ticks in a game loop?.


Microsoft support has a Knowledge Base article specifically about this:

How To Use QueryPerformanceCounter to Time Code

Basically you use QueryPerformanceCounter to get a high resolution timer value before and after the event you want to time.

Then use QueryPerformanceFrequency to get the number of ticks per second. Divide the time difference by this value to convert the value to seconds.


LARGE_INTEGER m_liPerformanceFrequency;
QueryPerformanceFrequency( &m_liPerformanceFrequency);

//...

LARGE_INTEGER liPerformanceCount;
QueryPerformanceCounter( &liPerformanceCount);
double dTime = double(liPerformanceCount.QuadPart)/double(m_liPerformanceFrequency.QuadPart);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜