title: clearing a small integer array: memset vs. for loop
body: <p>There are two ways to zero out an integer/float array:</p>
  
  <pre><code>memset(array, 0, sizeof(int)*arraysize);
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>for (int i=0; i &lt;arraysize; ++i)
      array[i]=0;
  </code></pre>
  
  <p>obviously, memset is faster for large <code>arraysize</code>. However, at what point is the overhead of memset actually larger than the overhead of the for loop? For example, for an array of size 5 - which would be best? The first, the 2nd, or maybe even the un-rolled version:</p>
  
  <pre><code>array[0] = 0;
  array[1] = 0;
  array[2] = 0;
  array[3] = 0;
  array[4] = 0;
  </code></pre>