title: Why does ComputeHash perform much slower then certutil -hashfile?
body: <p>I am looking for efficient way of calculating hash of big files (3GB) and realized that calling Windows certutil with argument <code>-hashfile</code> perform hash computation 4 time faster (16 sec) than doing it via <code>SHA512.Create().ComputeHash</code> (~60 sec) and I am not really understand such a big differences.</p>
  
  <p>I was trying to 'play' with reading buffer size of <code>FileStream</code> but it gives me about 2 sec so not really important optimization.</p>
  
  <p>1) Doing hash computation by ComputeHash:</p>
  
  <pre><code>var sw = Stopwatch.StartNew();
  using (var fs = new FileStream(@"C:\Temp\BigFile.dat", FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1024 * 1024 * 10, options: FileOptions.SequentialScan))
  {
      Console.WriteLine(BitConverter.ToString(SHA512.Create().ComputeHash(fs)));
  }
  Console.WriteLine(sw.ElapsedMilliseconds);
  </code></pre>
  
  <p>2) Doing it via certutil</p>
  
  <pre><code>var sw = Stopwatch.StartNew();
  var fPath = @"C:\Temp\BigFile.dat";
  var p = Process.Start(new ProcessStartInfo(@"certutil", $"-hashfile \"{fPath}\" SHA512") { RedirectStandardOutput = true, UseShellExecute=false});
  p.WaitForExit();
  Console.WriteLine(p.StandardOutput.ReadToEnd());
  Console.WriteLine(sw.ElapsedMilliseconds);
  </code></pre>
  
  <p>I would expect some difference in time due to managed/native nature of code but 16 sec vs 60 looks a bit confusing.</p>
  
  <p>At <a href="https://stackoverflow.com/questions/1177607/what-is-the-fastest-way-to-create-a-checksum-for-large-files-in-c-sharp">this question</a> it is also mentioned that native code works much faster but the are no explanation of this difference and I am mostly interested in understanding the difference. I was thinking that in nowadays it shouldnt be such a big difference in such simple example (IO + math?)</p>