Files
SPT-Server-Build/Libraries/Core/Utils/TimerUtil.cs
T
2025-01-19 17:45:48 +00:00

31 lines
643 B
C#

using System.Diagnostics;
using SptCommon.Annotations;
namespace Core.Utils
{
[Injectable]
public class TimerUtil
{
protected 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
};
}
}
}