# FPS variation

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

## Recommended Posts

hiya! I have just implemented a simple fps counter type function
void UpdateFPS()
{
fps.numFrames++;
float currentUpdate = timer.GetTime() / 1000;

if((currentUpdate - fps.lastUpdate) > fps.fpsUpdateInterval)
{
fps.count = fps.numFrames / (currentUpdate - fps.lastUpdate);
fps.lastUpdate = currentUpdate;
fps.numFrames = 0;
}
}

Easy enough. Question is, I get variations from 50-113 fps. Is there a good way to get a consistent rate?? Or is this normal?

##### Share on other sites
Looks perfectly reasonable to me (unless I missed something)

However... (hehe there *had* to be one coming)
There is a much simpler method all together which I perfer...
Screw framerate all together & use frame frequency instead:
frequency=1/frame time
Divide 1 second by the number of seconds passed since the last frame was rendered to get a reading of how many of those frames would fit in a second
Now you can have framerates that update every frame instead of every second or so.
It's only an estimate ofcourse & is based on the current time & not any actual counting of frames, but it's good enough for me ;]

Also I apply a slight "blur" between these readings:
Store the framerate in a seperate variable & compare to the frequency
if the frequency is lower then drop the framerate to it immediately, if it's higher then increase the framerate alittle bit

This helps to make slowdown more visible

It might seem "fake", but then counting frames across gaps like seconds isn't an entirely accurate way of reporting game speed either

You might of noticed that the fps display in many games (like quake 3) updates every frame rather than every second(time period)
That's coz it's actually frequency reading

##### Share on other sites
Yes, that's a common problem with that approach. More complicated methods can yield better results.

See previous discussions on this topic: 1 2 3.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634133
• Total Posts
3015734
×