Jump to content
  • Advertisement


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



This topic is 6152 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

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

Share this post

Link to post
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 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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!