protected void UpdateStatistics()
{
frameCount++;
var thisTime = _timer.Milliseconds;
// check frame time
var frameTime = thisTime - lastTime;
lastTime = thisTime;
stats.BestFrameTime = Math.Utility.Min(stats.BestFrameTime, frameTime);
stats.WorstFrameTime = Math.Utility.Max(stats.WorstFrameTime, frameTime);
// check if new second (update only once per second)
if (thisTime - lastSecond <= 1000)
return;
// new second - not 100% precise
stats.LastFPS = (float)frameCount / (thisTime - lastSecond) * 1000;
if (stats.AverageFPS == 0)
stats.AverageFPS = stats.LastFPS;
else
stats.AverageFPS = (stats.AverageFPS + stats.LastFPS) / 2; // not strictly correct, but good enough
stats.BestFPS = Math.Utility.Max(stats.BestFPS, stats.LastFPS);
stats.WorstFPS = Math.Utility.Min(stats.WorstFPS, stats.LastFPS);
lastSecond = thisTime;
frameCount = 0;
}