Stopwatch
This class wraps a System.Diagnostics.Stopwatch on operating systems that support it. On those that don't,
it replicates the functionality at the resolution supported.
using System.Diagnostics;
namespace NUnit.Framework.Compatibility
{
public class Stopwatch
{
private System.Diagnostics.Stopwatch _stopwatch = new System.Diagnostics.Stopwatch();
public long ElapsedMilliseconds => _stopwatch.ElapsedMilliseconds;
public bool IsRunning => _stopwatch.IsRunning;
public static long Frequency => System.Diagnostics.Stopwatch.Frequency;
public static bool IsHighResolution => System.Diagnostics.Stopwatch.IsHighResolution;
public static long GetTimestamp()
{
return System.Diagnostics.Stopwatch.GetTimestamp();
}
public void Reset()
{
_stopwatch.Reset();
}
public void Restart()
{
Reset();
Start();
}
public void Start()
{
_stopwatch.Start();
}
public static Stopwatch StartNew()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
return stopwatch;
}
public void Stop()
{
_stopwatch.Stop();
}
public override string ToString()
{
return _stopwatch.ToString();
}
}
}