我猜你想要的是这个:
// 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.