views:

500

answers:

6

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

+1  A: 

Find something like a high resolution timer (more than 1000 ticks/seconds), and measure the time between when you start rendering until it's on the screen.

Divide the ticks per second by the time you just measured, and you have the FPS.

Brammie
A: 

Check this thread out. There are some very useful links on it. Good luck!

Stringer Bell
+4  A: 

Try running:

Run -> Run With Performance Tool -> OpenGL ES.

You have to run that tool when connected to the device (which you'd obviously want to anyway for performance tuning...)

It gives you Core Animation FPS which may (probably) not be what you are looking for, but it can graph a number of other useful statistics for you which may also help you optimize.

Kendall Helmstetter Gelner
I am able to see FPS on my old ipod touch running 2.2.1 but not my new iphone 3gs running 3.1. It only gives coreanimation as an option...
Mel
Try running Instruments standalone, and attach to your running process - this lets you add whatever tool you like, where XCode sometimes gets confused about tools you are "allowed" to run.
Kendall Helmstetter Gelner
A: 

When you reach the end of your drawing code, increase a counter.

Setup an NSTimer fire every second, display the counter, and reset it to zero.

A: 

Measuring FPS during development is nearly meaningless. Measure the rendering time you need!

This way you will have a much clearer understanding of how your changes affect performance. Usually it's a very good idea to split your rendering time into meaningful slices, e.g. "render background", "render level", "render mobs", etc.

If you still want to do FPS my personal favourite is Johns NSTimer version, even if it doesn't show spikes.

Andreas
A: 

I guess what you want is this:

// fps calculation
static int m_nFps; // current FPS
static CFTimeInterval lastFrameStartTime; 
static int m_nAverageFps; // the average FPS over 15 frames
static int m_nAverageFpsCounter;
static int m_nAverageFpsSum;
static UInt8* m_pRGBimage;

static void calcFps()
{
    CFTimeInterval thisFrameStartTime = CFAbsoluteTimeGetCurrent();
    float deltaTimeInSeconds = thisFrameStartTime - lastFrameStartTime;
    m_nFps = (deltaTimeInSeconds == 0) ? 0: 1 / (deltaTimeInSeconds);

    m_nAverageFpsCounter++;
    m_nAverageFpsSum+=m_nFps;
    if (m_nAverageFpsCounter >= 15) // calculate average FPS over 15 frames
    {
        m_nAverageFps = m_nAverageFpsSum/m_nAverageFpsCounter;
        m_nAverageFpsCounter = 0;
        m_nAverageFpsSum = 0;
    }


    lastFrameStartTime = thisFrameStartTime;
}

Regards, Asaf Pinhassi.

Pinhassi