Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>MD5 and SHA1 rely on native implementaions, nonetheless its possible a C++ solution + introp could be slightly faster, cause you could possibly reduce the number of method calls a bit and optimize the native implementation. </p> <p>Keep in mind that the Native (SHA1CryptoServiceProvider) can be 3X faster than the managed one(SHA1Managed).</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Security.Cryptography; namespace ConsoleApplication22 { class Program { static void Profile(string description, int iterations, Action func) { // clean up GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); // warm up func(); var watch = Stopwatch.StartNew(); for (int i = 0; i &lt; iterations; i++) { func(); } watch.Stop(); Console.Write(description); Console.WriteLine(" Time Elapsed {0} ms", watch.ElapsedMilliseconds); } static void Main() { SHA1Managed managed = new SHA1Managed(); SHA1CryptoServiceProvider unmanaged = new SHA1CryptoServiceProvider(); Random rnd = new Random(); var buffer = new byte[100000]; rnd.NextBytes(buffer); Profile("managed", 1000, () =&gt; { managed.ComputeHash(buffer, 0, buffer.Length); }); Profile("unmanaged", 1000, () =&gt; { unmanaged.ComputeHash(buffer, 0, buffer.Length); }); Console.ReadKey(); } } } </code></pre> <pre> managed Time Elapsed 891 ms unmanaged Time Elapsed 336 ms </pre> <p><strong>Also Keep in mind</strong> unless my calculation is wrong, the unmanaged implementation is hashing 100MB of data in about 300 milliseconds, this would very rarely be a bottleneck. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload