Jump to content
  • Advertisement
Sign in to follow this  
gothicly

Measuring FPS

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

I know there are a lot of threads and tutorials on how to implement an fps counter.

For some reason though, no matter how much I read through those tutorials, or try to understand the code I can never get the logic behind a working fps measure.

I ask for your guidance, and your help, in explaining to me the full breadth of how an fps counter works.

If you could also give me information on how to use this logic with c++, eg: timer() functions, I would surely benefit from the logic and the corresponding code if it is not too much of a hassle.

I hope someone can help.

Share this post


Link to post
Share on other sites
Advertisement
Simple stupid FPS:

Update()
{
...
if (second_has_elapsed)
{
SetCurrentFPS(frames);
frames= 0;
}
frames++;
...
}




But raw FPS is not really a good indicator.

Imagine your screen refresh is 75 Hz, what you really want is an update <=13 ms. You could have a 75 Hz framerate with 1 frame taking 999 ms and the other 74 frames taking up 0 ms.

Much better to know are the total frame count along with the actual milliseconds for min/avg/max. If min or max get too far away from avg, you know you have some long or short frames.

Update()
{
...
if(second_has_elapsed)
{
if(!frames)
frames = 1; // prevent divide by zero.
avg_milliseconds = total_milliseconds/frames;
SetCurrentFramerate( frames, min_milliseconds, avg_milliseconds, max_milliseconds );
frames = 0;
min_milliseconds = INT_MAX;
max_milliseconds = 0;
total_milliseconds = 0;
}
frames++;
min_milliseconds = min ( current_frame_ms, min_milliseconds);
max_milliseconds = max ( current_frame_ms, max_milliseconds);
total_milliseconds += current_frame_ms;
...
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!