title: .NET Stopwatch - performance penalty
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/28637/is-datetime-now-the-best-way-to-measure-a-functions-performance">Is DateTime.Now the best way to measure a function&#39;s performance?</a><br>
    <a href="https://stackoverflow.com/questions/2923283/stopwatch-vs-using-system-datetime-now-for-timing-events">Stopwatch vs. using System.DateTime.Now for timing events</a>  </p>
  </blockquote>
  
  
  
  <p>I have code which needs to run as fast as possible. To be able to log the execution time, I use the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx" rel="noreferrer">Stopwatch</a> class. I suspect, Stopwatch may effect the performance in a bad way. Maybe using a DateTime difference may be more effective?</p>
  
  <p>Which one do you think has better performance?</p>
  
  <pre><code>Stopwatch sw = new Stopwatch();
  sw.Start();
  int a = 5;
  
  // Critical lines of code
  
  long elapsedMs = se.Elapsed.TotalMilliseconds;
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>DateTime startDate = DateTime.Now;
  int a = 5;
  
  // Critical lines of code
  
  long elapsedMs = DateTime.Now.Subtract(startDate).TotalMilleseconds;
  </code></pre>