Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • This is a great test. Unfortunately, in its current state it is flawed, making it seem like Stopwatch takes a lot more time to execute than what it actually does. In the stopwatch test you are doing an extra datetime operation (sw.ElapsedTicks == DateTime.Now.Ticks) which not only has to fetch the current time from the system clock, but prior to that also convert the datetime object into the current timezone since you're using DateTime.Now instead of DateTime.UtcNow. Thus you are actually testing the execution time of DateTime.Now + Stopwatch instead of Stopwach alone. Commented Sep 14, 2023 at 18:11
  • I downvoted in order to raise awareness of potential misinformation, but I will be happy to upvote instead if this is corrected. In order to make the test more correct, you should store the value of DateTime.(Utc)Now.Ticks prior to the loop instead, which actually makes Stopwatch the fastest when run on .NET 6 on my machine and on .NET Fiddle: dotnetfiddle.net/dSg3bN Commented Sep 14, 2023 at 18:13