Public Group

# 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.

## 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.

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 on other sites
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;...}

1. 1
2. 2
Rutin
21
3. 3
JoeJ
17
4. 4
5. 5

• 37
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631705
• Total Posts
3001823
×