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



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
// do some stuff that takes up time
//find the time
float time = (float)(end_count - start_count) / (float)freq;

Share this post

Link to post
Share on other sites