#### Archived

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

# QueryPerformanceTimer

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

## Recommended Posts

Can someone please post some code which shows how to use this function to measure the FPS rate of my code. Thanks.

##### Share on other sites
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 changeQueryPerformanceFrequency((LARGE_INTEGER*)&freq);QueryPerformanceCounter((LARGE_INTEGER*)&start_count);// do some stuff that takes up timeQueryPerformanceCounter((LARGE_INTEGER*)&end_count);//find the timefloat time = (float)(end_count - start_count) / (float)freq;

##### Share on other sites
Perfect!!!!! Thanks dude

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
17
5. 5

• 33
• 13
• 12
• 10
• 12
• ### Forum Statistics

• Total Topics
632575
• Total Posts
3007150

×