PDA

View Full Version : How to know FPSs?



pmatos
11-22-2003, 11:22 AM
Hi all,

What's the best way to know the frames per second of my opengl application?

Best regards,

Paulo Matos

11-22-2003, 11:41 AM
just create a counter variable and add 1 to it every time you display a frame. Then every 1 of couple of seconds, divide by the number of seconds that have passed. It probably best to just do it every second..

pmatos
11-22-2003, 01:12 PM
Originally posted by r_shadrach:
just create a counter variable and add 1 to it every time you display a frame. Then every 1 of couple of seconds, divide by the number of seconds that have passed. It probably best to just do it every second..


Do you mean to put a counter in the end of each display callback?

But if I'm always dividing for each frame I'll have a division per frame which will just bring programs efficiency down!

Best regards,

Paulo Matos

enmaniac
11-22-2003, 01:33 PM
You can do it like this:




void RenderScene()
{
static UINT uiFramesCounts = 0;
static DWORD dwLastTime = 0;

// Render here all the stuff you want

// Add 1 to indicate that next frame was shown

uiFrameCounts++;

// Check if 1 second passed

if ( dwLastTime-GetTickCount() >= 1000 )
{
// uiFrameCounts now shows FPS value
// which you can show on screen or whatever

// Reset frames counter

uiFrameCounts = 0;

// Store time last FPS show was done

dwLastTime = GetTickCounts();
}
}

zeckensack
11-22-2003, 10:42 PM
Originally posted by pmatos:
But if I'm always dividing for each frame I'll have a division per frame which will just bring programs efficiency down!What are you talking about!?

Worst case FDIV is 24 cycles on an Athlon.
Worst case expected target machine is 500 MHz.

That's twenty goddamn million float divisions per second and you're talking about losing efficiency because of doing it once per frame? Grrr ....

pmatos
11-23-2003, 02:30 PM
Can I put this piece of code in the registered idle function (if using glut)?

Is idle function called once per frame? (if not, then I cannot put the code there since I need a function that's called once per frame, right?)

Best regards,

Paulo Matos



Originally posted by enmaniac:
You can do it like this:




void RenderScene()
{
static UINT uiFramesCounts = 0;
static DWORD dwLastTime = 0;

// Render here all the stuff you want

// Add 1 to indicate that next frame was shown

uiFrameCounts++;

// Check if 1 second passed

if ( dwLastTime-GetTickCount() >= 1000 )
{
// uiFrameCounts now shows FPS value
// which you can show on screen or whatever

// Reset frames counter

uiFrameCounts = 0;

// Store time last FPS show was done

dwLastTime = GetTickCounts();
}
}

mikael_aronsson
11-23-2003, 11:24 PM
The idle function is called when there is "some time to spare", don't use it.

Of course you have something that is called "once per frame", you must render something wright ? put the code in there.

Mikael

Obli
11-24-2003, 05:16 AM
Originally posted by r_shadrach:
just create a counter variable and add 1 to it every time you display a frame. Then every 1 of couple of seconds, divide by the number of seconds that have passed. It probably best to just do it every second..

I don't do that because it's not uncommon to have the driver at work behind the scenes in the first few seconds of rendering. This is like an average ratio. I compute istant ratio between frames (I don't even require the division for who's interested to performance to this degree, I can do it with a mul and if you are smart with even less - i am not)...

The advantage of this is a more responsive FPS counter. So, if you get 999fps for a long time then pop in some heavyweight geometry which takes you down to 9fps, you immediatly see the difference. Using average fps would put the counter on 998 and this would look bad.

Having a per-frame period also have other useful advantages (I am sure most games are using this approach).

pmatos
11-24-2003, 05:29 AM
I think this is the approach taken by the above code (modulo some typos...).


Originally posted by Obli:
I don't do that because it's not uncommon to have the driver at work behind the scenes in the first few seconds of rendering. This is like an average ratio. I compute istant ratio between frames (I don't even require the division for who's interested to performance to this degree, I can do it with a mul and if you are smart with even less - i am not)...

The advantage of this is a more responsive FPS counter. So, if you get 999fps for a long time then pop in some heavyweight geometry which takes you down to 9fps, you immediatly see the difference. Using average fps would put the counter on 998 and this would look bad.

Having a per-frame period also have other useful advantages (I am sure most games are using this approach).

Wiggers
11-25-2003, 03:35 AM
I think:

if ( 999 < (GetTickCount() - dwLastTime) )

works a bit better. ;-)

Obli
11-25-2003, 12:11 PM
Originally posted by pmatos:
I think this is the approach taken by the above code (modulo some typos...).
Yes, looks out it is, I just wanted to point out some good reasons to do that instead of the averaging method.

fuxiulian
11-26-2003, 02:17 AM
Sorry to be a little late, but not the division is taking the time, but updating the caption of the window (if that is where you display your frame counter is).

I have made a FPS counter and showing it every other second or every other 100th frame improved my rendering speed. I have seen a 10x increase in framerate (from 50 to 500 or so).

To get rid of that and show the FPS every frame you could render the fps as text in your opengl window. (that's what I have done)

cwc36
11-26-2003, 03:51 AM
Hi,

You can get a frame per second demo in this url..... http://myopendemo.hypermart.net/opengl2.htm