title: std::vector vs std::array performance
body: <p>I was looking at the new chrono library (C++11) and trying to use it. I wrote the two following programs:</p>
  
  <p><strong>vector.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;chrono&gt;
  
  int main()
  {
      std::vector&lt;double&gt; vector(1000000, 0.);
  
      auto start = std::chrono::high_resolution_clock::now();
      for(int i(0); i &lt; vector.size(); i++)
      {
          vector[i] += 1.;
      }
      auto end = std::chrono::high_resolution_clock::now();
  
      std::cout &lt;&lt; "Elapsed time: " &lt;&lt; std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(end-start).count() &lt;&lt; " milliseconds" &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p><strong>array.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;array&gt;
  #include &lt;algorithm&gt;
  #include &lt;chrono&gt;
  
  int main()
  {
      std::array&lt;double, 1000000&gt; array;
  
      std::fill(array.begin(), array.end(), 0.);
  
      auto start = std::chrono::high_resolution_clock::now();
      for(int i(0); i &lt; array.size(); i++)
      {
          array[i] += 1.;
      }
      auto end = std::chrono::high_resolution_clock::now();
  
      std::cout &lt;&lt; "Elapsed time: " &lt;&lt; std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(end-start).count() &lt;&lt; " milliseconds" &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>I obtained 9 millisecond for the array program and 12 milliseconds for the vector program. The  std::vector seems about 33% slower than the std::array. I'm doing it right? Why this difference?</p>
  
  <p>Ps: I'm using GCC 4.7, Mac OS X 10.7.</p>
  
  <pre><code>g++-mp-4.7 -std=c++11 vector.cpp -o vector
  g++-mp-4.7 -std=c++11 array.cpp -o array
  </code></pre>