From 07cad087335fbdc85e68b7a432925aaca5a3380c Mon Sep 17 00:00:00 2001 From: Parnic Date: Tue, 14 Dec 2021 12:48:45 -0600 Subject: [PATCH] Add ability to name timers --- src/Timer.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Timer.cs b/src/Timer.cs index 7a67964..1390627 100644 --- a/src/Timer.cs +++ b/src/Timer.cs @@ -5,6 +5,13 @@ namespace aoc2021 internal class Timer : IDisposable { private readonly Stopwatch stopwatch = Stopwatch.StartNew(); + private readonly string? name; + + public Timer(string? inName = null) + { + name = inName; + } + public void Dispose() { stopwatch.Stop(); @@ -18,7 +25,7 @@ namespace aoc2021 { color = "[33m"; } - Logger.Log($"Took \u001b{color}{elapsed:N1}{unit}\u001b[0m"); + Logger.Log($"{name}{(!string.IsNullOrEmpty(name) ? " t" : "T")}ook \u001b{color}{elapsed:N1}{unit}\u001b[0m"); } public (double elapsed, string unit) ConvertElapsedToHumanReadable()