From 9cdb590d9f7484a85e2e91aa7f7a22f2f6c85cf9 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 21 Aug 2018 14:57:19 -0400 Subject: [PATCH] fix: Slightly more accurate profile times --- ICD.Common.Utils/Timers/IcdStopwatch.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/ICD.Common.Utils/Timers/IcdStopwatch.cs b/ICD.Common.Utils/Timers/IcdStopwatch.cs index 8434f02..8e0e6d0 100644 --- a/ICD.Common.Utils/Timers/IcdStopwatch.cs +++ b/ICD.Common.Utils/Timers/IcdStopwatch.cs @@ -106,7 +106,7 @@ namespace ICD.Common.Utils.Timers IcdStopwatch stopwatch = StartNew(); action(); - PrintProfile(stopwatch, name); + PrintProfile(stopwatch.ElapsedTicks, name); } /// @@ -122,12 +122,9 @@ namespace ICD.Common.Utils.Timers if (func == null) throw new ArgumentNullException("func"); - T output = default(T); - - Profile(() => - { - output = func(); - }, name); + IcdStopwatch stopwatch = StartNew(); + T output = func(); + PrintProfile(stopwatch.ElapsedTicks, name); return output; } @@ -213,7 +210,7 @@ namespace ICD.Common.Utils.Timers { if (eventHandler == null) { - PrintProfile(new IcdStopwatch(), string.Format("{0} - No invocations", name)); + PrintProfile(0, string.Format("{0} - No invocations", name)); return; } @@ -244,7 +241,7 @@ namespace ICD.Common.Utils.Timers { if (eventHandler == null) { - PrintProfile(new IcdStopwatch(), string.Format("{0} - No invocations", name)); + PrintProfile(0, string.Format("{0} - No invocations", name)); return; } @@ -262,9 +259,9 @@ namespace ICD.Common.Utils.Timers } } - private static void PrintProfile(IcdStopwatch stopwatch, string name) + private static void PrintProfile(long ticks, string name) { - float elapsed = stopwatch.ElapsedTicks / (float)TimeSpan.TicksPerMillisecond; + float elapsed = ticks / (float)TimeSpan.TicksPerMillisecond; eConsoleColor color = eConsoleColor.Green; if (elapsed >= YELLOW_MILLISECONDS)