Skip to content

Commit

Permalink
Merge pull request #6122 from peppy/frame-calc-delegate-overhead
Browse files Browse the repository at this point in the history
Remove delegate allocation in jitter calculation in `FramedClock`
  • Loading branch information
bdach authored Jan 11, 2024
2 parents 450946d + 3e30306 commit 8346f6c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions osu.Framework/Timing/FramedClock.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Extensions.TypeExtensions;
using System;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Extensions.TypeExtensions;

namespace osu.Framework.Timing
{
Expand Down Expand Up @@ -85,9 +84,18 @@ public virtual void ProcessFrame()
FramesPerSecond = (int)Math.Ceiling(framesSinceLastCalculation * 1000f / timeSinceLastCalculation);

// simple stddev
double avg = betweenFrameTimes.Average();
double stddev = Math.Sqrt(betweenFrameTimes.Average(v => Math.Pow(v - avg, 2)));
Jitter = stddev;
double sum = 0;
double sumOfSquares = 0;

foreach (double v in betweenFrameTimes)
{
sum += v;
sumOfSquares += v * v;
}

double avg = sum / betweenFrameTimes.Length;
double variance = (sumOfSquares / betweenFrameTimes.Length) - (avg * avg);
Jitter = Math.Sqrt(variance);
}

timeSinceLastCalculation = framesSinceLastCalculation = 0;
Expand Down

0 comments on commit 8346f6c

Please sign in to comment.