From 889ed157fe22c84cf929e3329494bce88a78bb96 Mon Sep 17 00:00:00 2001 From: Zaafar Date: Sun, 21 Mar 2021 12:54:21 -0400 Subject: [PATCH] Removed Avg, Max and added raw stats i.e LastMoveNextTime --- Coroutine/ActiveCoroutine.cs | 15 +++++---------- Example/Example.cs | 3 +-- Tests/TimeBasedCoroutineTests.cs | 16 ++++------------ 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/Coroutine/ActiveCoroutine.cs b/Coroutine/ActiveCoroutine.cs index e6f8314..dd0ec8e 100644 --- a/Coroutine/ActiveCoroutine.cs +++ b/Coroutine/ActiveCoroutine.cs @@ -36,15 +36,11 @@ namespace Coroutine { /// public int MoveNextCount { get; private set; } /// - /// The maximum amount of time that took. - /// This is the maximum amount of time that each "step", or each yield statement, of this coroutine took to execute. + /// The amount of time that the last took. + /// This is the amount of time that this active coroutine took for the last "step", or yield statement. /// - public TimeSpan MaxMoveNextTime { get; private set; } - /// - /// The average amount of time that took. - /// This is the average amount of time that each "step", or each yield statement, of this coroutine took to execute. - /// - public TimeSpan AverageMoveNextTime => new TimeSpan(this.TotalMoveNextTime.Ticks / this.MoveNextCount); + public TimeSpan LastMoveNextTime { get; private set; } + /// /// An event that gets fired when this active coroutine finishes or gets cancelled. /// When this event is called, is always true. @@ -97,9 +93,8 @@ namespace Coroutine { this.stopwatch.Restart(); var result = this.enumerator.MoveNext(); this.stopwatch.Stop(); + this.LastMoveNextTime = this.stopwatch.Elapsed; this.TotalMoveNextTime += this.stopwatch.Elapsed; - if (this.stopwatch.Elapsed > this.MaxMoveNextTime) - this.MaxMoveNextTime = this.stopwatch.Elapsed; this.MoveNextCount++; if (!result) { diff --git a/Example/Example.cs b/Example/Example.cs index 88b899d..543817e 100644 --- a/Example/Example.cs +++ b/Example/Example.cs @@ -56,8 +56,7 @@ namespace Example { Console.WriteLine("By the way, the first coroutine has finished!"); Console.WriteLine($"{first.Name} data: {first.MoveNextCount} moves, " + $"{first.TotalMoveNextTime.TotalMilliseconds} total time, " + - $"{first.AverageMoveNextTime.TotalMilliseconds} average, " + - $"{first.MaxMoveNextTime.TotalMilliseconds} maximum"); + $"{first.LastMoveNextTime.TotalMilliseconds} last time"); Environment.Exit(0); } } diff --git a/Tests/TimeBasedCoroutineTests.cs b/Tests/TimeBasedCoroutineTests.cs index a13eb55..2e0fa46 100644 --- a/Tests/TimeBasedCoroutineTests.cs +++ b/Tests/TimeBasedCoroutineTests.cs @@ -313,7 +313,7 @@ namespace Tests { } [Test] - public void CoroutineStatsAre95PercentAccurate() { + public void CoroutineStatsAreUpdated() { static IEnumerator CoroutineTakesMax500Ms() { Thread.Sleep(200); yield return new Wait(10); @@ -324,17 +324,9 @@ namespace Tests { for (var i = 0; i < 5; i++) CoroutineHandler.Tick(50); - const int expected1 = 350; - const float errorbar1 = 5 / 100f * expected1; - var gTa = cr.AverageMoveNextTime.Milliseconds > expected1 - errorbar1; // 95% accuracy. - var lTb = cr.AverageMoveNextTime.Milliseconds < expected1 + errorbar1; // 95% accuracy. - Assert.IsTrue(gTa && lTb, $"Average Move Next Time {cr.AverageMoveNextTime.Milliseconds} is invalid."); - - const int expected2 = 500; - const float errorbar2 = 5 / 100f * expected2; - var gTc = cr.MaxMoveNextTime.Milliseconds > expected2 - errorbar2; // 95% accuracy. - var lTd = cr.MaxMoveNextTime.Milliseconds < expected2 + errorbar2; // 95% accuracy. - Assert.IsTrue(gTc && lTd, $"Maximum Move Next Time {cr.MaxMoveNextTime.Milliseconds} is invalid."); + Assert.IsTrue(cr.TotalMoveNextTime.TotalMilliseconds >= 700); + Assert.IsTrue(cr.LastMoveNextTime.TotalMilliseconds >= 500); + Assert.IsTrue(cr.MoveNextCount == 2); } [Test]