title: Slow writing to array in C++
body: <p>I was just wondering if this is expected behavior in C++. The code below runs at around 0.001 ms:</p>
  
  <pre><code>for(int l=0;l&lt;100000;l++){
          int total=0;
          for( int i = 0; i &lt; num_elements; i++) 
          {
              total+=i;
          }
      }
  </code></pre>
  
  <p>However if the results are written to an array, the time of execution shoots up to 15 ms:</p>
  
  <pre><code>int *values=(int*)malloc(sizeof(int)*100000);
          for(int l=0;l&lt;100000;l++){
              int total=0;
              for( unsigned int i = 0; i &lt; num_elements; i++) 
              {
                  total+=i;
              }
              values[l]=total;
          }
  </code></pre>
  
  <p>I can appreciate that writing to the array takes time but is the time proportionate?</p>
  
  <p>Cheers everyone</p>