Skip to content

Commit

Permalink
refactor: Faster IsLastMeasurementExpired
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilien Noal <noal.maximilien@gmail.com>
  • Loading branch information
maximilien-noal committed Nov 10, 2024
1 parent 744e755 commit bd8bb94
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Spice86.Shared/Diagnostics/PerformanceMeasurer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ private void ResetMetrics(long newTimeInMilliseconds) {
AverageValuePerSecond = 0;
}

private bool IsLastMeasurementExpired(long newTimeInMilliseconds) {
return (TimeSpan.FromTicks(newTimeInMilliseconds) - TimeSpan.FromTicks(_firstMeasureTimeInMilliseconds)).TotalSeconds >= WindowSizeInSeconds;
}
private bool IsLastMeasurementExpired(long newTimeInMilliseconds) =>
newTimeInMilliseconds - _firstMeasureTimeInMilliseconds > WindowSizeInSeconds * 1000;

private static long ApproxRollingAverage(long measureAverage, long valuePerSecond, long sampledMetricsCount) {
measureAverage -= measureAverage / Math.Max(sampledMetricsCount, 1);
Expand Down

0 comments on commit bd8bb94

Please sign in to comment.