Let's do some simple benchmarking of various hash functions to see how they compare performance-wise. In the following code snippet, we define a method for running our tests, similar to the one for the previous collection benchmarks:
private static long RunTest(Action func, int runs = 1000) { var s = Stopwatch.StartNew(); for (int j = 0; j < runs; j++) { func(); } s.Stop(); return s.ElapsedMilliseconds; }
We include the following using statement:
using System.Security.Cryptography;
Next, we define a short private constant string (hashingData) to hash in the class and get the bytes for it in an 8-bit Unicode (UTF8) format:
var smallBytes = Encoding.UTF8.GetBytes(hashingData);
We also want to get a larger block of bytes ...