English 中文(简体)
Calculate fps (frames per second) for iphone app
原标题:

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?

最佳回答

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.

问题回答

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.

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.

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.

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

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.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签