Changed timing from using Stopwatch to DateTime ticks for consitent time resolution between different environments
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Xander Sigler 2023-12-09 21:16:31 -08:00
parent 98466729ab
commit 1f94ff2ca9
3 changed files with 7 additions and 11 deletions

View File

@ -25,10 +25,9 @@ namespace AdventOfCode.Models
public AOCResponse ExecuteDay(AOCRequest request)
{
_request = request;
var timer = new Stopwatch();
try
{
timer.Start();
var startTicks = DateTime.UtcNow.Ticks;
switch (request.Version)
{
case AOCVersion.A:
@ -38,12 +37,8 @@ namespace AdventOfCode.Models
this._response = ExecutePartB();
break;
}
timer.Stop();
Console.WriteLine($"Elapsed ticks is {timer.ElapsedTicks.ToString()}");
Console.WriteLine($"System Clock Resolution: {TimeSpan.FromTicks(Stopwatch.Frequency).TotalSeconds} seconds");
Console.WriteLine($"Local Time Zone: {TimeZoneInfo.Local}");
Console.WriteLine($"Current System Time: {DateTime.Now}");
this._response.RunTime = timer.ElapsedTicks.ToString();
this._response.RunTime = (DateTime.UtcNow.Ticks - startTicks).ToString();
this._response.Status = true;
}
catch (Exception e)

View File

@ -4,6 +4,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
@ -13,6 +14,9 @@ namespace AdventOfCode
{
public static void Main(string[] args)
{
Console.WriteLine($"System Clock Resolution: {TimeSpan.FromTicks(Stopwatch.Frequency).TotalSeconds} seconds");
Console.WriteLine($"Local Time Zone: {TimeZoneInfo.Local}");
Console.WriteLine($"Current System Time: {DateTime.Now}");
CreateHostBuilder(args).Build().Run();
}

View File

@ -1,10 +1,7 @@
using AdventOfCode.Common;
using AdventOfCode.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace AdventOfCode._2023
{