Files
SPT-Server-Build/Core/Utils/TimerUtil.cs
T
2025-01-14 19:30:15 +00:00

31 lines
645 B
C#

using System.Diagnostics;
using Core.Annotations;
namespace Core.Utils
{
[Injectable]
public class TimerUtil
{
private readonly Stopwatch _stopwatch;
public TimerUtil()
{
_stopwatch = new Stopwatch();
_stopwatch.Start();
}
public int Stop(string unit = "sec")
{
_stopwatch.Stop();
var timePassed = _stopwatch.Elapsed;
return unit switch
{
"ns" => timePassed.Nanoseconds,
"ms" => timePassed.Milliseconds,
_ => timePassed.Seconds
};
}
}
}