Sign in to follow this  
gothicly

Measuring FPS

Recommended Posts

gothicly    177
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
frob    44975
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this