Skip to main content
gamedev.net
🔒 Locked

Average fps

Started by Ruudje 1 reply 450+ views
Original Post
Ruudje
Ruudje
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...
Enigma
Enigma
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]
Ruudje
Ruudje
omg cant believe i didnt realise that

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.