private static void PerformBenchmark(HashLookupBase hashClass, int size) { var sw = Stopwatch.StartNew(); for (int i = 0; i < size; i++) { hashClass.AddHash(BitConverter.GetBytes(i * 2)); } Console.WriteLine("Hashing and addition took " + sw.ElapsedMilliseconds + "ms"); sw.Restart(); hashClass.CompleteAdding(); Console.WriteLine("Hash cleanup (sorting, usually) took " + sw.ElapsedMilliseconds + "ms"); sw.Restart(); var found = 0; for (int i = 0; i < size * 2; i += 10) { found += hashClass.Contains(BitConverter.GetBytes(i)) ? 1 : 0; } Console.WriteLine("Found " + found + " elements (expected " + (size / 5) + ") in " + sw.ElapsedMilliseconds + "ms"); }
private static void PerformBenchmark(HashLookupBase hashClass, int size = 150000000) { var sw = Stopwatch.StartNew(); for (int i = 0; i < size; i++) { hashClass.AddHash(BitConverter.GetBytes(i)); } Console.WriteLine("Hashing and addition took " + sw.ElapsedMilliseconds + "ms"); sw.Restart(); hashClass.CompleteAdding(); Console.WriteLine("Hash cleanup (sorting, usually) took " + sw.ElapsedMilliseconds + "ms"); sw.Restart(); var random = new Random(); var found = 0; var maxValue = (int)(size * 1.25); for (int i = 0; i < 10000000; i++) { found += hashClass.Contains(BitConverter.GetBytes(random.Next(maxValue))) ? 1 : 0; } Console.WriteLine("Found " + found + " elements in " + sw.ElapsedMilliseconds + "ms"); }