QueryPerformanceTimer

Started by
1 comment, last by Ibanez 22 years, 5 months ago
Can someone please post some code which shows how to use this function to measure the FPS rate of my code. Thanks.
Advertisement
There are two functions you have to worry about.... QueryPerformanceFrequency and QueryPerformanceCounter... QueryPerformanceFreqency (QPF) find how many times the counter is updated per second, or it''s Hz. The QueryPerformanceCounter (QPC) gets the current number of ticks that have elapsed since Windows started (or the PC, I don''t know where the origin is). So to find the amount of time, we make two successive calls to QPC and subtract them. This gives us the amount of ticks have elapsed. Then to convert from ticks to seconds, just divide by the frequency. For example, if the frequency is 10Hz and the difference of the two QPC calls is 10, then 1 second has elapsed. Like this. I''m using visual C++ for this and I use the __int64 so that I don''t have to manage the LARGE_INTEGER structure.

__int64 start_count;
__int64 end_count;
__int64 freq;

// Get the frequency and save it, it shouldn''t change
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
QueryPerformanceCounter((LARGE_INTEGER*)&start_count);
// do some stuff that takes up time
QueryPerformanceCounter((LARGE_INTEGER*)&end_count);
//find the time
float time = (float)(end_count - start_count) / (float)freq;
Perfect!!!!! Thanks dude

This topic is closed to new replies.

Advertisement