HighPrecisionTimeStamps NuGet Package

It is well known that DateTime.Now is often used inappropriately.

For example, it may be used together with TimeSpan to produce a task's timeout point or subtracted from another DateTime to calculate a duration. This can cause subtle bugs because DateTime is not monotonic: the system clock can change, making the result of the subtraction inaccurate -- potentially causing a premature timeout or an infinite loop. Yet, DateTime is an incredibly convenient and widely used value type in .NET code and is especially useful when printed in ISO-8601 format (with the "O" format specifier).

With the "O" specifier, you can resolution down to tenths of a microsecond, which is nice.

Until you learn that the resolution of the system clock is usually more coarse than several *milliseconds*, making the additional decimal places misleading garbage values. For calculating durations (time between events), it is better to use a high-resolution and monotonic clock like that provided by System.Diagnostics.Stopwatch: on most computers it is far more **accurate** than DateTime.Now even though, seemingly paradoxically, on a few systems, its *resolution* is lower than that of DateTime. Also, unsurprisingly, Stopwatch does not provide values that correlate to times of day: while it is appropriate for calculating durations, it is inappropriate for timestamping against a readable date and time.

This library provides timestamps (both as DateTime and as analogous value types it defines) that use the Stopwatch (and your system's high peformance event counter) as its clock, but returns values as DateTimes or an analog thereto so that these values can be used for a mixed purpose of timestamping and providing a meaningful way to calculate time elapsed between events or to calculate how long to perform a programmatic task.




Got any HighPrecisionTimeStamps Question?





Info

Version: 1.0.0.7-beta
Author(s): Christopher P. Susie
Last Update: Tuesday, February 1, 2022
.NET Fiddle: Create the first Fiddle
Project Url: https://github.com/cpsusie/High-Precision-Time-Stamps
NuGet Url: https://www.nuget.org/packages/HighPrecisionTimeStamps


Install
Install-Package HighPrecisionTimeStamps
dotnet add package HighPrecisionTimeStamps
paket add HighPrecisionTimeStamps
HighPrecisionTimeStamps Download (Unzip the "nupkg" after downloading)



Tags



STATS

must-have-score

.3

avg-downloads-per-day

1

days-since-last-release

815