comment 0

Professional Development – 2024 – Week 44

Image Credit: https://www.flickr.com/photos/54585499@N04/

.NET

How to Measure Time Correctly in .NET (via Nick Chapsas)

  • Capturing two DateTime.UtcNow values and subtracting isn’t the most accurate approach because there are many other considerations going on (e.g., leap seconds).
  • When using the Stopwatch class, there’s some overhead for having to allocate it on the heap.
  • In .NET 7 we got Stopwatch.GetTimestamp() which returns a 64-bit value. This gets a value from the operation system.
  • Final Answer: Use StopWatch.GetTimestamp() with Stopwatch.GetElapsedTime(myStartTime).

The Best Way to Work with Units in .NET (via Nick Chapas)

  • When dealing with units of measurement, check out the NuGet library UnitsNet.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.