Archived

This topic is now archived and is closed to further replies.

QueryPerformanceTimer

This topic is 5871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;

Share this post


Link to post
Share on other sites