about summary refs log tree commit diff
path: root/lib/Extensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Extensions.cs')
-rw-r--r--lib/Extensions.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Extensions.cs b/lib/Extensions.cs
index a1ffbcc..eb8c3cb 100644
--- a/lib/Extensions.cs
+++ b/lib/Extensions.cs
@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 
 namespace aoc2019.lib
@@ -28,5 +29,20 @@ namespace aoc2019.lib
                 foreach (var item in sequence)
                     yield return item;
         }
+
+        /// <summary>
+        ///     increased accuracy for stopwatch based on frequency.
+        ///     <see
+        ///         href="http://geekswithblogs.net/BlackRabbitCoder/archive/2012/01/12/c.net-little-pitfalls-stopwatch-ticks-are-not-timespan-ticks.aspx">
+        ///         blog
+        ///         details here
+        ///     </see>
+        /// </summary>
+        /// <param name="stopwatch"></param>
+        /// <returns></returns>
+        public static double ScaleMilliseconds(this Stopwatch stopwatch)
+        {
+            return 1_000 * stopwatch.ElapsedTicks / (double) Stopwatch.Frequency;
+        }
     }
 }
\ No newline at end of file