fix: Slightly more accurate profile times

This commit is contained in:
Chris Cameron
2018-08-21 14:57:19 -04:00
parent ca10f049e5
commit 9cdb590d9f

View File

@@ -106,7 +106,7 @@ namespace ICD.Common.Utils.Timers
IcdStopwatch stopwatch = StartNew(); IcdStopwatch stopwatch = StartNew();
action(); action();
PrintProfile(stopwatch, name); PrintProfile(stopwatch.ElapsedTicks, name);
} }
/// <summary> /// <summary>
@@ -122,12 +122,9 @@ namespace ICD.Common.Utils.Timers
if (func == null) if (func == null)
throw new ArgumentNullException("func"); throw new ArgumentNullException("func");
T output = default(T); IcdStopwatch stopwatch = StartNew();
T output = func();
Profile(() => PrintProfile(stopwatch.ElapsedTicks, name);
{
output = func();
}, name);
return output; return output;
} }
@@ -213,7 +210,7 @@ namespace ICD.Common.Utils.Timers
{ {
if (eventHandler == null) if (eventHandler == null)
{ {
PrintProfile(new IcdStopwatch(), string.Format("{0} - No invocations", name)); PrintProfile(0, string.Format("{0} - No invocations", name));
return; return;
} }
@@ -244,7 +241,7 @@ namespace ICD.Common.Utils.Timers
{ {
if (eventHandler == null) if (eventHandler == null)
{ {
PrintProfile(new IcdStopwatch(), string.Format("{0} - No invocations", name)); PrintProfile(0, string.Format("{0} - No invocations", name));
return; 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; eConsoleColor color = eConsoleColor.Green;
if (elapsed >= YELLOW_MILLISECONDS) if (elapsed >= YELLOW_MILLISECONDS)