DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="2.9.1" />

 Timestamp

Represents timestamp.
using System; using System.Diagnostics; using System.Runtime.CompilerServices; namespace DotNext.Diagnostics { public readonly struct Timestamp : IEquatable<Timestamp>, IComparable<Timestamp> { private readonly long ticks; public static Timestamp Current => new Timestamp(Stopwatch.GetTimestamp()); public TimeSpan Value => new TimeSpan(ToTicks((double)ticks)); public TimeSpan Elapsed => new TimeSpan(ToTicks((double)Math.Max(0, Stopwatch.GetTimestamp() - ticks))); private Timestamp(long ticks) { this.ticks = ticks; } private static long ToTicks(double duration) { return (long)(10000000 * duration / (double)Stopwatch.Frequency); } public static implicit operator TimeSpan(Timestamp stamp) { return stamp.Value; } public bool Equals(Timestamp other) { return ticks == other.ticks; } public int CompareTo(Timestamp other) { return ticks.CompareTo(other.ticks); } [System.Runtime.CompilerServices.NullableContext(2)] public override bool Equals(object other) { if (other is Timestamp) { Timestamp other2 = (Timestamp)other; return Equals(other2); } return false; } public override int GetHashCode() { return ticks.GetHashCode(); } [System.Runtime.CompilerServices.NullableContext(1)] public override string ToString() { return Value.ToString(); } public static bool operator ==(Timestamp first, Timestamp second) { return first.ticks == second.ticks; } public static bool operator !=(Timestamp first, Timestamp second) { return first.ticks != second.ticks; } public static bool operator >(Timestamp first, Timestamp second) { return first.ticks > second.ticks; } public static bool operator <(Timestamp first, Timestamp second) { return first.ticks < second.ticks; } public static bool operator >=(Timestamp first, Timestamp second) { return first.ticks >= second.ticks; } public static bool operator <=(Timestamp first, Timestamp second) { return first.ticks <= second.ticks; } } }