From 02ecff187d64aa381695d7a9083695419f519a63 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 9 Mar 2018 13:49:13 -0500 Subject: [PATCH] Method for profiling each step in an enumerable --- ICD.Common.Utils/Timers/IcdStopwatch.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ICD.Common.Utils/Timers/IcdStopwatch.cs b/ICD.Common.Utils/Timers/IcdStopwatch.cs index d6d1810..1f9f398 100644 --- a/ICD.Common.Utils/Timers/IcdStopwatch.cs +++ b/ICD.Common.Utils/Timers/IcdStopwatch.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using ICD.Common.Properties; #if SIMPLSHARP using Crestron.SimplSharp; @@ -128,6 +129,22 @@ namespace ICD.Common.Utils.Timers return output; } + /// + /// Profiles getting each item from the enumerable. + /// + /// + /// + /// + /// + public static IEnumerable Profile(IEnumerable enumerable, string name) + { + using (IEnumerator enumerator = enumerable.GetEnumerator()) + { + while (Profile(() => enumerator.MoveNext(), name)) + yield return enumerator.Current; + } + } + private static void PrintProfile(IcdStopwatch stopwatch, string name) { long elapsed = stopwatch.ElapsedMilliseconds;