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

@ -19,5 +19,16 @@ namespace AOC2021.Models
public IEnumerable<string> Debug { get; set; } public IEnumerable<string> Debug { get; set; }
[DataMember] [DataMember]
public string StackTrace { get; set; } 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