I made a small test application in C # that sets DateTime.Now and starts StopWatch . Every ten seconds I print _stopwatch.Elapsed.TotalMilliseconds and (DateTime.Now - _startTime).TotalMilliseconds .
Until I expect both to be the same, I was surprised to see that they diverged linearly by about one millisecond in 20 seconds. I assume DateTime.Now calls the system clock, and StopWatch do some accumulation?
Output Example:
StopWatch : 0,2 DateTime : 1,0 Diff : 0,81 StopWatch : 10000,5 DateTime : 10002,6 Diff : 2,04 (...) StopWatch : 2231807,5 DateTime : 2231947,7 Diff : 140,13 StopWatch : 2241809,5 DateTime : 2241950,2 Diff : 140,70
Full source: https://gist.github.com/knatten/86529563122a342de6bb
Exit: https://gist.github.com/knatten/84f9be9019ee63119ee2
c #
knatten
source share