Struct Timestamp
Represents timestamp.
Implements
Inherited Members
Namespace: DotNext.Diagnostics
Assembly: DotNext.dll
Syntax
public readonly record struct Timestamp : IComparable<Timestamp>, IComparisonOperators<Timestamp, Timestamp, bool>, IEqualityOperators<Timestamp, Timestamp, bool>, IAdditionOperators<Timestamp, TimeSpan, Timestamp>, ISubtractionOperators<Timestamp, TimeSpan, Timestamp>, IInterlockedOperations<Timestamp>, IEquatable<Timestamp>
Remarks
This class can be used as allocation-free alternative to Stopwatch.
Constructors
| Edit this page View SourceTimestamp()
Captures the current point in time.
Declaration
public Timestamp()
Timestamp(TimeProvider)
Captures the current point in time.
Declaration
public Timestamp(TimeProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeProvider | provider | The time provider. |
Timestamp(TimeSpan)
Constructs timestamp from TimeSpan.
Declaration
public Timestamp(TimeSpan ts)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | ts | The point in time. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Properties
| Edit this page View SourceElapsed
Gets precise difference between the current point in time and this timestamp.
Declaration
public TimeSpan Elapsed { get; }
Property Value
| Type | Description |
|---|---|
| TimeSpan |
Remarks
This property is always greater than or equal to Zero.
ElapsedMilliseconds
Gets the total elapsed time measured by the current instance, in milliseconds.
Declaration
public double ElapsedMilliseconds { get; }
Property Value
| Type | Description |
|---|---|
| double |
ElapsedTicks
Gets the total elapsed time measured by the current instance, in timer ticks.
Declaration
public long ElapsedTicks { get; }
Property Value
| Type | Description |
|---|---|
| long |
IsEmpty
Gets a value indicating that the timestamp is zero.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsFuture
Gets a value indicating that the current timestamp represents the future point in time.
Declaration
public bool IsFuture { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsPast
Gets a value indicating that the current timestamp represents the past point in time.
Declaration
public bool IsPast { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Value
Gets TimeSpan representing this timestamp.
Declaration
public TimeSpan Value { get; }
Property Value
| Type | Description |
|---|---|
| TimeSpan |
Remarks
This property may return a value with lost precision.
Methods
| Edit this page View SourceCompareExchange(ref Timestamp, Timestamp, Timestamp)
Compares two values for equality and, if they are equal, replaces the first value.
Declaration
public static Timestamp CompareExchange(ref Timestamp location, Timestamp value, Timestamp comparand)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | location | The destination, whose value is compared with comparand and possibly replaced. |
| Timestamp | value | The value that replaces the destination value if the comparison results in equality. |
| Timestamp | comparand | The value that is compared to the value at |
Returns
| Type | Description |
|---|---|
| Timestamp | The original value in |
CompareTo(Timestamp)
Compares this timestamp with the given value.
Declaration
public int CompareTo(Timestamp other)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | other | The timestamp to compare. |
Returns
| Type | Description |
|---|---|
| int | The result of comparison. |
ElapsedSince(Timestamp)
Gets a difference between two timestamps, in milliseconds.
Declaration
public double ElapsedSince(Timestamp past)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | past | The timestamp in the past. |
Returns
| Type | Description |
|---|---|
| double | The number of milliseconds since |
ElapsedSince(Timestamp, TimeProvider)
Gets a difference between two timestamps, in milliseconds.
Declaration
public double ElapsedSince(Timestamp past, TimeProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | past | The timestamp in the past. |
| TimeProvider | provider | Time provider. |
Returns
| Type | Description |
|---|---|
| double | The number of milliseconds since |
GetElapsedMilliseconds(TimeProvider)
Gets the total elapsed time measured by the current instance, in milliseconds.
Declaration
public double GetElapsedMilliseconds(TimeProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeProvider | provider | Time provider. |
Returns
| Type | Description |
|---|---|
| double | The elapsed time, in ms, between the starting timestamp and the time of this call. |
GetElapsedTicks(TimeProvider)
Gets the total elapsed time measured by the current instance, in timer ticks.
Declaration
public long GetElapsedTicks(TimeProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeProvider | provider | Time provider. |
Returns
| Type | Description |
|---|---|
| long | The elapsed time, in ticks, between the starting timestamp and the time of this call. |
GetElapsedTime(TimeProvider)
Gets precise difference between the current point in time and this timestamp.
Declaration
public TimeSpan GetElapsedTime(TimeProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeProvider | provider | Time provider. |
Returns
| Type | Description |
|---|---|
| TimeSpan | The elapsed time between the starting timestamp and the time of this call. |
Refresh(ref Timestamp)
Updates the timestamp to the current point in time and prevents the processor from reordering memory operations.
Declaration
public static void Refresh(ref Timestamp location)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | location | The location of the timestamp to update. |
Refresh(ref Timestamp, TimeProvider)
Updates the timestamp to the current point in time and prevents the processor from reordering memory operations.
Declaration
public static void Refresh(ref Timestamp location, TimeProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | location | The location of the timestamp to update. |
| TimeProvider | provider | Time provider. |
ToString()
Gets timestamp in the form of the string.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | The string representing this timestamp. |
Overrides
| Edit this page View SourceVolatileRead(ref readonly Timestamp)
Reads the timestamp and prevents the processor from reordering memory operations.
Declaration
public static Timestamp VolatileRead(ref readonly Timestamp location)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | location | The managed pointer to the timestamp. |
Returns
| Type | Description |
|---|---|
| Timestamp | The value at the specified location. |
VolatileWrite(ref Timestamp, Timestamp)
Writes the timestamp and prevents the processor from reordering memory operations.
Declaration
public static void VolatileWrite(ref Timestamp location, Timestamp newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | location | The managed pointer to the timestamp. |
| Timestamp | newValue | The value to write. |
Operators
| Edit this page View Sourceoperator +(Timestamp, TimeSpan)
Adds the specified duration to the timestamp.
Declaration
public static Timestamp operator +(Timestamp x, TimeSpan y)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | x | The timestamp value. |
| TimeSpan | y | The delta. |
Returns
| Type | Description |
|---|---|
| Timestamp | The modified timestamp. |
operator checked +(Timestamp, TimeSpan)
Adds the specified duration to the timestamp.
Declaration
public static Timestamp operator checked +(Timestamp x, TimeSpan y)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | x | The timestamp value. |
| TimeSpan | y | The delta. |
Returns
| Type | Description |
|---|---|
| Timestamp | The modified timestamp. |
Exceptions
| Type | Condition |
|---|---|
| OverflowException |
|
operator checked -(Timestamp, TimeSpan)
Subtracts the specified duration from the timestamp.
Declaration
public static Timestamp operator checked -(Timestamp x, TimeSpan y)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | x | The timestamp value. |
| TimeSpan | y | The delta. |
Returns
| Type | Description |
|---|---|
| Timestamp | The modified timestamp. |
Exceptions
| Type | Condition |
|---|---|
| OverflowException |
|
explicit operator TimeSpan(Timestamp)
Gets TimeSpan representing the given timestamp.
Declaration
public static explicit operator TimeSpan(Timestamp stamp)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | stamp | The timestamp to convert. |
Returns
| Type | Description |
|---|---|
| TimeSpan |
Remarks
This operation leads to loss of precision.
operator >(Timestamp, Timestamp)
Determines whether the first timestamp is greater than the second.
Declaration
public static bool operator >(Timestamp first, Timestamp second)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | first | The first timestamp to compare. |
| Timestamp | second | The second timestamp to compare. |
Returns
| Type | Description |
|---|---|
| bool | true if |
operator >=(Timestamp, Timestamp)
Determines whether the first timestamp is greater than or equal to the second.
Declaration
public static bool operator >=(Timestamp first, Timestamp second)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | first | The first timestamp to compare. |
| Timestamp | second | The second timestamp to compare. |
Returns
| Type | Description |
|---|---|
| bool | true if |
operator <(Timestamp, Timestamp)
Determines whether the first timestamp is less than the second.
Declaration
public static bool operator <(Timestamp first, Timestamp second)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | first | The first timestamp to compare. |
| Timestamp | second | The second timestamp to compare. |
Returns
| Type | Description |
|---|---|
| bool | true if |
operator <=(Timestamp, Timestamp)
Determines whether the first timestamp is less than or equal to the second.
Declaration
public static bool operator <=(Timestamp first, Timestamp second)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | first | The first timestamp to compare. |
| Timestamp | second | The second timestamp to compare. |
Returns
| Type | Description |
|---|---|
| bool | true if |
operator -(Timestamp, TimeSpan)
Subtracts the specified duration from the timestamp.
Declaration
public static Timestamp operator -(Timestamp x, TimeSpan y)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | x | The timestamp value. |
| TimeSpan | y | The delta. |
Returns
| Type | Description |
|---|---|
| Timestamp | The modified timestamp. |
Exceptions
| Type | Condition |
|---|---|
| OverflowException |
|