title: Why is this CRC32 implementation in C# so slow?
body: <p>I'm using the following function to compute the CRC32 of a file in a VS2008, .NET 3.5 project:</p>
  
  <pre><code>public UInt32 ComputeHash(System.IO.Stream stream)
  {
      unchecked
      {
          const int BUFFER_SIZE = 1024;
  
          UInt32 crc32Result = 0xFFFFFFFF;
          byte[] buffer = new byte[BUFFER_SIZE];
          int count = stream.Read(buffer, 0, BUFFER_SIZE);
  
          while (count &gt; 0)
          {
              for (int i = 0; i &lt; count; i++)
              {
                  crc32Result = ((crc32Result) &gt;&gt; 8) ^ _crc32Table[(buffer[i]) ^ (crc32Result) &amp; _LOOKUP_TABLE_MAX_INDEX];
              }
              count = stream.Read(buffer, 0, BUFFER_SIZE);
          }
  
          return ~crc32Result;
      }
  }
  </code></pre>
  
  <p>For the sake of brevity, I have left out the function that builds the lookup table (_crc32Table).   The table is an array of UInt32, is built when the class is instantiated, and contains 256 values (256 is also the value of _LOOKUP_TABLE_MAX_INDEX + 1).</p>
  
  <p>I have run some benchmarks comparing this to the MD5CryptoServiceProvider and SHA1CryptoServiceProvider ComputeHash functions and they are much faster.  The MD5 function is over twice as fast and the SHA1 hash is about 35% faster.  I was told CRC32 is fast, but that's not what I'm seeing.</p>
  
  <p>Am I mistaken in my assumptions?  Is this to be expected or is there a flaw in this algorithm?</p>