title: Slow While loop in C#
body: <p>I have a <code>while</code> loop and all it does is a method call. I have a timer on the outside of the loop and another timer that incrementally adds up the time the method call takes inside the loop. The outer time takes about 17 seconds and the total on the inner timer is 40 ms. The loop is executing 50,000 times. Here is an example of the code:</p>
  
  <pre><code>long InnerTime = 0;
  long OutterTime = 0;
  Stopw1.Start();
  int count = 1;
  while (count &lt;= TestCollection.Count) {
      Stopw2.Start();
      Medthod1();
      Stopw2.Stop();
      InnerTime = InnerTime + Stopw2.ElapsedMilliseconds;
      Stopw2.Reset();
      count++;
  }
  Stopw1.Stop();
  OutterTime = Stopw1.ElapsedMilliseconds;
  Stopw1.Reset();
  </code></pre>
  
  <p>Any help would be much appreciated.
  Massimo</p>