Removed Avg, Max and added raw stats i.e LastMoveNextTime

This commit is contained in:
Zaafar 2021-03-21 12:54:21 -04:00
parent 0e5b571590
commit 889ed157fe
3 changed files with 10 additions and 24 deletions

View file

@ -36,15 +36,11 @@ namespace Coroutine {
/// </summary>
public int MoveNextCount { get; private set; }
/// <summary>
/// The maximum amount of time that <see cref="MoveNext"/> 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 <see cref="MoveNext"/> took.
/// This is the amount of time that this active coroutine took for the last "step", or yield statement.
/// </summary>
public TimeSpan MaxMoveNextTime { get; private set; }
/// <summary>
/// The average amount of time that <see cref="MoveNext"/> took.
/// This is the average amount of time that each "step", or each yield statement, of this coroutine took to execute.
/// </summary>
public TimeSpan AverageMoveNextTime => new TimeSpan(this.TotalMoveNextTime.Ticks / this.MoveNextCount);
public TimeSpan LastMoveNextTime { get; private set; }
/// <summary>
/// An event that gets fired when this active coroutine finishes or gets cancelled.
/// When this event is called, <see cref="IsFinished"/> 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) {

View file

@ -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);
}
}

View file

@ -313,7 +313,7 @@ namespace Tests {
}
[Test]
public void CoroutineStatsAre95PercentAccurate() {
public void CoroutineStatsAreUpdated() {
static IEnumerator<Wait> 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]