FPS calculation

Started by
6 comments, last by Nice Coder 18 years, 11 months ago
I have a couple of questions related to the seemingly trivial task of calculating FPS for my application. I'm running the following code to calculate my frame rate: This is called once every frame. //update number of frames gs_FPScounter++; //no. seconds passed gs_nextSecond = timeGetTime() * 0.001f; if ( gs_nextSecond - gs_prevSecond > 1.0f ) { gs_prevSecond = gs_nextSecond; gs_FPS = gs_FPScounter; gs_FPScounter = 0; } I get, for my relatively simple app ( rotating cubes ), a frame rate of of around 67fps. two points 1. this is incredibly low given the hardware configuration I'm running it on ( P4m GF Go 5200 ).It should be higher. I've run D3D apps that give higher frame rates ( over 100 ) on my machine. 2. It could be that my refresh rate is bound to 60Hz(lap top screen won't go any higher), and I'm rendering using a double buffer and VSync. This still makes no sense as my FPS should be capped at 60fps.So why 67fps. Mark
Advertisement
You might want to change this..
gs_prevSecond = gs_nextSecond;
to this..
gs_prevSecond += 1.0f;

Should be slightly more accurate. Other than that, everything looks fine. Have you tried disabling the refresh rate with..
Present.FullScreen_RefreshRateInHz = D3DPRESENT_INTERVAL_IMMEDIATE ?

I'm not sure what else (unless your rendering loop?) could cause problems.
Quote:Original post by MarkyMark
2. It could be that my refresh rate is bound to 60Hz(lap top screen won't go any higher), and I'm rendering using a double buffer and VSync. This still makes no sense as my FPS should be capped at 60fps.So why 67fps.


Could be because (gs_nextSecond - gs_prevSecond) won't be exactly 1.0, as you assume. It will more likely be a little bigger than that. So it should be:

gs_FPS = gs_FPScounter/(gl_NextSecond-gs_prevSecond);

Anyway, measuring your FPS with VSync on is not a good idea. Turn it off.

I have'nt worked out why yet, but for some reason
changing gs_prevSecond = gs_nextSecond to gs_prevSecond += 1.0f
resulting in my FPS showing up as 1

Make sure gs_prevSecond is initialized to timeGetTime() * 0.001f on startup.

edit:

It would have eventually caught up after a while. Possibly hours [smile]
Thanks that did the job.

Its now capped at 60Hz which is what I would have expected from
my hardware configuration.

Now to try and measure the frame rate without VSync.


Mark

some things still bother me.

I ran the demo by turning DOUBLE BUFFERING off in the pixel format
descriptor ( this is OpenGL ) and removing the SwapBuffer call
at the end of the game loop.

The frame goes up ( max 180fps at 800x400 ) but the display is
very jittery. I'm assuming this is to be expected. Am I right?

now for my point of confusion...

As I see it the situation is either
1) max frame rate of 60fps with double buffering turned on
2) max frame rate of 180fps with double buffering turned off, but jittery

but..

I'm running some of the D3D samples, and I'm getting very high
frame rates on some of them e.g 640fps on Text3D (w/o jitter ) and I don't understand how.




fps = 1000 / Avg;
// Avg is the average time per frame. (in ms)
//To calculate avg...

//Nice-Code

tmr += timeneeded
cnt++;
if (cnt = 32) {avg = tmr & 31; tmr = 0; cnt = 0;}
fps = 1000 / avg;

//Just be sure to init avg to 1.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.

This topic is closed to new replies.

Advertisement