Advertisement

FPS-how do you know

Started by January 09, 2000 01:52 PM
6 comments, last by thekid 25 years, 1 month ago
how do you put something in your game loop that calculates your fps?
The most accurate way is to count the number of frames displayed, and then divide by the number of seconds the program runs (duh). The problem with that method is that you''ll only get your data when the program has terminated, which is normally not what you would want.

What you could do is take samples (any "Real Time" action can be approximated by a collection of discrete samples). The simple approach is to decide on an interval (which will be different for every program), and then at the end of each interval divide by the number of seconds (or milliseconds, whatever) that passed during that interval. For example:

if(framecounter == interval) {
FPS = framecounter / (CurrentTime - OldTime)
OldTime = CurrentTime
framecounter = 0
}

Just remember to increment framecounter everytime a new frame is displayed.
------When thirsty for life, drink whisky. When thirsty for water, add ice.
Advertisement
i found that incrementing a counter every frame until 1 sec is reached works well. just store the number and reset the counter.
-werdup-
that and it takes all of like 3 lines of code or whatever to implement, heh
-werdup-
Some people also like to know worse case frame rate. If you want to track something like that, simply store the longest time it takes to execute one frame and take the inverse of that.
Another way to measure FPS would be to count the time between two frames with a highresolution counter, then divide it by the frequency of the counter and multiply it by the number of frames. Due to the fact that you calculated the time between only two frames, you could leave out the multiplication because the number of frames is always 1. This results in the equation
fps = deltaTime / freq
In Windows, the functions for highresolution counters are
QueryPerformanceFreq()
QueryPerformanceCounter()

(I'm not quite sure, correct me if I'm wrong)

Edited by - Chappa on 1/10/00 6:13:39 AM
Advertisement
Chappa, that would only give you the FPS between those two frames. If it happens to be the a scene where everything is blowing up, particle effect galore, etc. Then it might give a misleading snapshot of FPS. Same problem if it happened to be two empty scenes. Just choosing two consecutive frames at random doesn''t really tell you much.

You really do need to keep track of total times over a number of frames to get a realistic FPS estimate, unless you''re trying to compute a best case or worst case scenario.

You can tell I spent way too much time reading about FPS benchmarking on Quake.
Yup, I totally agree with you.
But you could update your average fps every frame and not every now and then.

This topic is closed to new replies.

Advertisement