Method for profiling each step in an enumerable

This commit is contained in:
Chris Cameron
2018-03-09 13:49:13 -05:00
parent cffe850bd7
commit 02ecff187d

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using ICD.Common.Properties; using ICD.Common.Properties;
#if SIMPLSHARP #if SIMPLSHARP
using Crestron.SimplSharp; using Crestron.SimplSharp;
@@ -128,6 +129,22 @@ namespace ICD.Common.Utils.Timers
return output; return output;
} }
/// <summary>
/// Profiles getting each item from the enumerable.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="enumerable"></param>
/// <param name="name"></param>
/// <returns></returns>
public static IEnumerable<T> Profile<T>(IEnumerable<T> enumerable, string name)
{
using (IEnumerator<T> enumerator = enumerable.GetEnumerator())
{
while (Profile(() => enumerator.MoveNext(), name))
yield return enumerator.Current;
}
}
private static void PrintProfile(IcdStopwatch stopwatch, string name) private static void PrintProfile(IcdStopwatch stopwatch, string name)
{ {
long elapsed = stopwatch.ElapsedMilliseconds; long elapsed = stopwatch.ElapsedMilliseconds;