Stopwatch vs. using System.DateTime.Now for timing events

Posted by Randy Minder on Stack Overflow See other posts from Stack Overflow or by Randy Minder
Published on 2010-05-27T17:16:23Z Indexed on 2010/05/27 17:21 UTC
Read the original article Hit count: 164

Filed under:

I wanted to track the performance of a piece of my application so I initially stored the start time using System.DateTime.Now and the end time also using System.DateTime.Now. The difference between the two was how long my code took to execute.

I noticed though that the difference didn't appear to be accurate. So I tried using a Stopwatch object. This turned out to be much, much more accurate.

Can anyone tell me why Stopwatch would be more accurate than calculating the difference between a start and end time using System.DateTime.Now?

Thanks.

© Stack Overflow or respective owner

Related posts about c#