Add approximate run time using StopWatch
This commit is contained in:
13
Program.cs
13
Program.cs
@@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using AdventOfCode.Days;
|
using AdventOfCode.Days;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
@@ -13,23 +14,35 @@ var select = new SelectionPrompt<Day>()
|
|||||||
|
|
||||||
var selectedDay = AnsiConsole.Prompt(select);
|
var selectedDay = AnsiConsole.Prompt(select);
|
||||||
|
|
||||||
|
var stopWatch = new Stopwatch();
|
||||||
|
|
||||||
AnsiConsole.MarkupLine($"[cyan]Running [yellow]{selectedDay}[/]...[/]\n");
|
AnsiConsole.MarkupLine($"[cyan]Running [yellow]{selectedDay}[/]...[/]\n");
|
||||||
|
|
||||||
AnsiConsole.MarkupLine("[cyan]Part [yellow]1[/] result:[/]");
|
AnsiConsole.MarkupLine("[cyan]Part [yellow]1[/] result:[/]");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
stopWatch.Start();
|
||||||
selectedDay.RunPart1();
|
selectedDay.RunPart1();
|
||||||
|
stopWatch.Stop();
|
||||||
|
|
||||||
|
AnsiConsole.MarkupLine($"[red]Approximate run time: [yellow]{stopWatch.ElapsedTicks / (double)Stopwatch.Frequency * 1000:F3} ms[/][/]");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
AnsiConsole.WriteException(e);
|
AnsiConsole.WriteException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopWatch.Reset();
|
||||||
|
|
||||||
AnsiConsole.MarkupLine("\n[cyan]Part [yellow]2[/] result:[/]");
|
AnsiConsole.MarkupLine("\n[cyan]Part [yellow]2[/] result:[/]");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
stopWatch.Start();
|
||||||
selectedDay.RunPart2();
|
selectedDay.RunPart2();
|
||||||
|
stopWatch.Stop();
|
||||||
|
|
||||||
|
AnsiConsole.MarkupLine($"[red]Approximate run time: [yellow]{stopWatch.ElapsedTicks / (double)Stopwatch.Frequency * 1000:F3} ms[/][/]");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user