init
This commit is contained in:
22
Common/DTS.Common/Utils/ValueStopWatch.cs
Normal file
22
Common/DTS.Common/Utils/ValueStopWatch.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user