added MaxMoveNextTime Stat to ActiveCoroutine.

This commit is contained in:
Zaafar 2021-01-01 00:21:17 -05:00
parent a77c9874e7
commit 013b846fbc
2 changed files with 13 additions and 1 deletions

View file

@ -33,6 +33,11 @@ namespace Coroutine {
/// </summary> /// </summary>
public int MoveNextCount { get; private set; } public int MoveNextCount { get; private set; }
/// <summary> /// <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.
/// </summary>
public TimeSpan MaxMoveNextTime { get; private set; }
/// <summary>
/// The average amount of time that <see cref="MoveNext"/> took. /// 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. /// This is the average amount of time that each "step", or each yield statement, of this coroutine took to execute.
/// </summary> /// </summary>
@ -88,6 +93,10 @@ namespace Coroutine {
var result = this.enumerator.MoveNext(); var result = this.enumerator.MoveNext();
this.stopwatch.Stop(); this.stopwatch.Stop();
this.TotalMoveNextTime += this.stopwatch.Elapsed; this.TotalMoveNextTime += this.stopwatch.Elapsed;
if (this.stopwatch.Elapsed > this.MaxMoveNextTime)
{
this.MaxMoveNextTime = this.stopwatch.Elapsed;
}
this.MoveNextCount++; this.MoveNextCount++;
if (!result) { if (!result) {

View file

@ -50,7 +50,10 @@ namespace Test {
Console.WriteLine("The time is " + DateTime.Now); Console.WriteLine("The time is " + DateTime.Now);
if (first.IsFinished) { if (first.IsFinished) {
Console.WriteLine("By the way, the first coroutine has finished!"); Console.WriteLine("By the way, the first coroutine has finished!");
Console.WriteLine($"{first.Name} data: {first.MoveNextCount} moves, {first.TotalMoveNextTime} total time, {first.AverageMoveNextTime} average"); Console.WriteLine($"{first.Name} data: {first.MoveNextCount} moves, " +
$"{first.TotalMoveNextTime.TotalMilliseconds} total time, " +
$"{first.AverageMoveNextTime.TotalMilliseconds} average, " +
$"{first.MaxMoveNextTime.TotalMilliseconds} maximum");
Environment.Exit(0); Environment.Exit(0);
} }
} }