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

时间:2009-11-15 18:14:23

标签: iphone opengl

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

6 个答案:

答案 0 :(得分: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;
}

此致 Asaf Pinhassi。

答案 1 :(得分:4)

尝试跑步:

Run -> Run With Performance Tool -> OpenGL ES

连接到设备时你必须运行该工具(显然你想要进行性能调整......)

它为你提供了核心动画FPS,它可能(可能)不是你想要的,但它可以为你绘制一些其他有用的统计数据,这也可以帮助你优化。

答案 2 :(得分:1)

找到类似高分辨率计时器(超过1000刻度/秒)的东西, 并测量开始渲染到屏幕之间的时间。

将每秒的刻度除以您刚刚测量的时间,并获得FPS。

答案 3 :(得分:1)

当您到达绘图代码的末尾时,请增加一个计数器。

每秒设置一次NSTimer激活,显示计数器,并将其重置为零。

答案 4 :(得分:0)

检查this线程。它上面有一些非常有用的链接。祝你好运!

答案 5 :(得分:0)

在开发过程中测量FPS几乎毫无意义。 测量您需要的渲染时间!

通过这种方式,您可以更清楚地了解更改如何影响性能。 通常,将渲染时间分成有意义的切片是一个非常好的主意,例如“渲染背景”,“渲染级别”,“渲染怪物”等。

如果您仍然想要做FPS,我个人最喜欢的是Johns NSTimer版本,即使它没有显示峰值。

相关问题