From 270cac64a4005ffdbb17067d1583b646e6537ad8 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 7 Dec 2019 04:11:19 -0500 Subject: [PATCH] add stopwatch benchmarking --- Day.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Day.cs b/Day.cs index ccd06c6..54c4b5d 100644 --- a/Day.cs +++ b/Day.cs @@ -11,11 +11,23 @@ namespace aoc2019 public virtual IEnumerable Input => File.ReadLines($"input/day{DayNumber}.in"); - public virtual void AllParts() + public virtual void AllParts(bool verbose = false) { Console.WriteLine($"Day {DayNumber}:"); - Console.WriteLine(Part1()); - Console.WriteLine(Part2()); + var s = new Stopwatch(); + s.Start(); + var part1 = Part1(); + s.Stop(); + if (verbose) Console.WriteLine($"part 1 elapsed ticks: {s.ElapsedTicks}"); + Console.WriteLine(part1); + + s.Reset(); + s.Start(); + var part2 = Part2(); + s.Stop(); + if (verbose) Console.WriteLine($"part 2 elapsed ticks: {s.ElapsedTicks}"); + Console.WriteLine(part2); + Console.WriteLine(); } public abstract string Part1();