title: What can I do to make this loop run faster?
body: <p>I have this simple loop:</p>
  
  <pre><code>int[] array = new int[100000000];
  int sum = 0;
  for (int i = 0; i &lt; array.Length; i++)
      sum += array[i];
  </code></pre>
  
  <p>I compared its performance with its C++ version. I though that the performance should be near the same, because it is very simple code and the range checks are omitted in that case. But it turned out that the C++ version is almost three times faster. So I have implemented C# unsafe version but the performance was even worse.
  Resharper suggests to convert the loop to linq expression like this:</p>
  
  <pre><code>sum = array.Sum();
  </code></pre>
  
  <p>That code is many times slower than the original loop in C#</p>
  
  <p>Could someone tell me if there is something more that I can do to improve the performance of this loop <strike>(without compiling it to 64 bit version - which is two times faster).</strike></p>
  
  <p>All test where made on 32 bit Release version and run without debugger.</p>
  
  <p>Edit: 
  Small correction. 64 bit version is two times faster with doubles, not ints</p>