RobustStopwatch
Namespace: SnowBank.Numerics · struct
Helper for measuring precise elapsed time
Remarks
This type is used as a shim for Stopwatch for .NET 7 or lower.
If you are on .NET 8 or higher, you can use GetTimestamp and GetElapsedTime directly.
Properties
Elapsed
TimeSpan Elapsed { get; }
Returns the elapsed time
ElapsedTicks
long ElapsedTicks { get; }
Returns the elapsed time (in ticks)
IsRunning
bool IsRunning { get; }
Tests if the stopwatch is running
MinimumResolution
static TimeSpan MinimumResolution { get; }
Returns the resolution of the stopwatch, i.e. the minimum time interval that can be measured
Methods
GetElapsedTime
static TimeSpan GetElapsedTime(long startingTimestamp)
Computes the elapsed time since the given timestamp
static TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp)
Computes the elapsed time between two timestamps
GetTimestamp
static long GetTimestamp()
Returns a timestamp for the current time
Reset
void Reset()
Stops and reset the stopwatch
Restart
void Restart()
Restarts the stopwatch
Start
void Start()
Starts the stopwatch
StartNew
static RobustStopwatch StartNew()
Creates a new stopwatch with the clock already running
Stop
TimeSpan Stop()
Stops the stopwatch
ToString
string ToString()