Archived

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

Average fps

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

Hey all, Id like to calculate the AVERAGE framerate aswel as the normal fps. The normal fps is working, but the average isnt. Im trying to do so like this:
// global
long active = 0; // amount of seconds the program is active
int average_fps = 0; // duh

// in the loop
..
active++;
average_fps = (average_fps + fps) / active;
..
 
By the time of the line active++; fps contains the current framerate. Im not sure why, but something is going wrong. If I let my program run for a while, the average_fps keeps getting lower and lower...

Share this post


Link to post
Share on other sites
OK, lets look at this:
Assume constant fps of 100.
t = 0: active = 0, average_fps = 0.
t = 1: active = 1, average_fps = (0 + 100) / 1 = 100
t = 2: active = 2, average_fps = (100 + 100) / 2 = 100
t = 3: active = 3, average_fps = (100 + 100) / 3 = 66.67
t = 4: active = 4, average_fps = (66.67 + 100) / 4 = 41.67

Now I'm going to guess what you mean by 'normal' and 'average' fps:
normal fps = fps at any particular instant
average fps = total frames rendered / total time taken

For this your average_fps formula should be:
average_fps = ((previous_average_fps * number_of_seconds_of_previous_fps) + (current_fps * number_of_seconds_of_current_fps)) / total_time_so_far
or:
average_fps = ((average_fps * (active - 1)) + fps) / active

Enigma

EDIT: just realised I'd said "Assume constant fps of 60.", but used 100!

[edited by - Enigma on November 28, 2003 12:17:43 PM]

Share this post


Link to post
Share on other sites