So I wrote my own script for calculating framerate but it consistently comes out with a different value than Unitys idea of current framerate.
This is my implementation
void UpdateFPSStats()
{
double frameTime = new double();
frameTime = Time.deltaTime;
m_times[frameIndex] = frameTime;
frameIndex++;
if (frameIndex == m_numberFrames)
{
frameIndex = 0;
}
int numberSamples = 0;
double averageFrameTime = 0.0f;
foreach(double t in m_times)
{
numberSamples++;
averageFrameTime += t;
}
if (numberSamples > 0)
{
averageFrameTime = averageFrameTime / numberSamples;
m_frameRate = 1 / averageFrameTime;
}
}
where m_frames is a list of the last 60 frames frame times and UpdateFPSStats is called in Unitys Update(dt)
function.
On average in my scene my fps calculation gives a steady 50fps, while Unity calculates a steady 80fps.
Which is right and why?