计算iPhone应用程序的fps(每秒帧数)

Mel*_*Mel 2 opengl iphone

我正在使用opengl es iphone应用程序.计算性能调优应用程序每秒帧数的最准确方法是什么?

Asa*_*ssi 5

我猜你想要的是这个:

// 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;
}
Run Code Online (Sandbox Code Playgroud)

此致,Asaf Pinhassi.