#### Archived

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

# Average fps

This topic is 5466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
omg cant believe i didnt realise that

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633312
• Total Posts
3011312
• ### Who's Online (See full list)

There are no registered users currently online

×