Calculating frames per second in a game

You need a smoothed average, the easiest way is to take the current answer (the time to draw the last frame) and combine it with the previous answer.

// eg.
float smoothing = 0.9; // larger=more smoothing
measurement = (measurement * smoothing) + (current * (1.0-smoothing))

By adjusting the 0.9 / 0.1 ratio you can change the ‘time constant’ – that is how quickly the number responds to changes. A larger fraction in favour of the old answer gives a slower smoother change, a large fraction in favour of the new answer gives a quicker changing value. Obviously the two factors must add to one!

Leave a Comment