using System; using System.Diagnostics; namespace DTS.Common.Utils { public readonly struct ValueStopwatch { private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency; private readonly long _startTimestamp; private ValueStopwatch(long startTimestamp) => _startTimestamp = startTimestamp; public static ValueStopwatch StartNew() => new ValueStopwatch(Stopwatch.GetTimestamp()); public TimeSpan GetElapsedTime() { var end = Stopwatch.GetTimestamp(); var elapsedTicks = (long)((end - _startTimestamp) * TimestampToTicks); return new TimeSpan(elapsedTicks); } } }