Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate fps (frames per second) for iphone app

Tags:

iphone

opengl

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?

like image 464
Mel Avatar asked Mar 28 '26 08:03

Mel


1 Answers

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.

like image 111
Asaf Pinhassi Avatar answered Mar 29 '26 22:03

Asaf Pinhassi