Struct Timestamp
Represents timestamp.
Implements
Inherited Members
Namespace: DotNext.Diagnostics
Assembly: DotNext.dll
Syntax
public readonly struct Timestamp : IComparable<Timestamp>, IComparisonOperators<Timestamp, Timestamp, bool>, IEqualityOperators<Timestamp, Timestamp, bool>, IAdditionOperators<Timestamp, TimeSpan, Timestamp>, ISubtractionOperators<Timestamp, TimeSpan, Timestamp>, IEquatable<Timestamp>
Remarks
This class can be used as allocation-free alternative to Stopwatch.
Constructors
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
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
View SourceCompareExchange(ref Timestamp, Timestamp, Timestamp)
Declaration
public static Timestamp CompareExchange(ref Timestamp location, Timestamp value, Timestamp comparand)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | location | |
| Timestamp | value | |
| Timestamp | comparand |
Returns
| Type | Description |
|---|---|
| Timestamp |
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 |
Equals(Timestamp)
Declaration
public bool Equals(Timestamp other)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | other |
Returns
| Type | Description |
|---|---|
| bool |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
View SourceGetElapsedMilliseconds(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. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
View SourceRefresh(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
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
View Sourceexplicit 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.
Explicit Interface Implementations
View Sourceoperator +(Timestamp, TimeSpan)
Adds the specified duration to the timestamp.
Declaration
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
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
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 ==(Timestamp, Timestamp)
Declaration
static bool operator ==(Timestamp left, Timestamp right)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | left | |
| Timestamp | right |
Returns
| Type | Description |
|---|---|
| bool |
operator >(Timestamp, Timestamp)
Determines whether the first timestamp is greater than the second.
Declaration
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
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)
Declaration
static bool operator !=(Timestamp left, Timestamp right)
Parameters
| Type | Name | Description |
|---|---|---|
| Timestamp | left | |
| Timestamp | right |
Returns
| Type | Description |
|---|---|
| bool |
operator <(Timestamp, Timestamp)
Determines whether the first timestamp is less than the second.
Declaration
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
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
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 |
|