title: Making a C code run faster
body: <p>I have written a piece of code which is used for counting the frequency of numbers between 0 and 255.</p>
  
  <pre><code>unsigned char arr[4096]; //aligned 64 bytes, filled with random characters
  
  short counter[256]; //aligned 32 bytes
  
  register int i;
  
  for(i = 0; i &lt; 4096; i++)
      ++counter[arr[i]];
  </code></pre>
  
  <p>It is taking a lot of time to execute; the random access to counter array is very expensive.</p>
  
  <p>Does anyone have any ideas which I could use to either make the accesses sequential or any other approach I could use?</p>