Still using two DateTime.Now calls to determine the duration of a certain call execution, like beneath?
1 2 3 | DateTime start = DateTime.Now; DoSomeCall(); double secondsToLog = (DateTime.Now - start).TotalSeconds; |
This is not at all necessary: using the StopWatch class. The StopWatch class is more efficient than any other solution provided or created in .NET since it uses low-level API calls and supports a high-resolution performance counter (when there is hardware and software support).
1 2 3 4 5 | Stopwatch watch = new Stopwatch(); watch.Start(); DoSomeCall(); watch.Stop(); double secondsToLog = watch.Elapsed.TotalSeconds; |