Added Run time for response answer

master
Xander Sigler 3 years ago
parent 494ad5f1dd
commit b6de95b807

@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace AOC2021.Models
{
@ -23,8 +24,10 @@ namespace AOC2021.Models
public AOCResponse ExecuteDay(AOCRequest request)
{
_request = request;
var timer = new Stopwatch();
try
{
timer.Start();
switch (request.Version)
{
case AOCVersion.A:
@ -34,6 +37,8 @@ namespace AOC2021.Models
this._response = ExecutePartB();
break;
}
timer.Stop();
this._response.RunTime = timer.ElapsedMilliseconds.ToString();
this._response.Status = true;
}
catch (Exception e)

@ -19,5 +19,16 @@ namespace AOC2021.Models
public IEnumerable<string> Debug { get; set; }
[DataMember]
public string StackTrace { get; set; }
private string timeInMs;
[DataMember]
public string RunTime { get { return FormatRunTime(); } set { timeInMs = value; } }
public string FormatRunTime()
{
var ts = TimeSpan.FromMilliseconds(Convert.ToDouble(timeInMs));
return $"Run time is {ts.Hours}h {ts.Minutes}min {ts.Seconds}sec {ts.Milliseconds}ms";
}
}
}

Loading…
Cancel
Save