public void CuckooHash_Compare_Large_Dictionary_Miss_Speeds() { int howLarge = 50000; Stopwatch cuckooStopwatch = new Stopwatch(); CuckooHash <string, string> cuckooHash = new CuckooHash <string, string>(); new IDictionaryTest().Insert_Random(cuckooHash, howLarge); cuckooStopwatch.Start(); for (int i = 0; i < howLarge; i++) { // ReSharper disable once UnusedVariable bool holder = cuckooHash.ContainsKey(Util.RandomString(10)); } cuckooStopwatch.Stop(); Stopwatch dictionaryStopwatch = new Stopwatch(); Dictionary <string, string> dictionary = new Dictionary <string, string>(); new IDictionaryTest().Insert_Random(dictionary, howLarge); dictionaryStopwatch.Start(); for (int i = 0; i < howLarge; i++) { // ReSharper disable once UnusedVariable bool holder = cuckooHash.ContainsKey(Util.RandomString(10)); } dictionaryStopwatch.Stop(); Console.Out.WriteLine("Cuckoo hash took " + cuckooStopwatch.ElapsedMilliseconds + " milliseconds."); Console.Out.WriteLine("Dictionary took " + dictionaryStopwatch.ElapsedMilliseconds + " milliseconds."); Console.Out.WriteLine("Difference is " + (Math.Max(cuckooStopwatch.ElapsedMilliseconds, dictionaryStopwatch.ElapsedMilliseconds) - Math.Min(cuckooStopwatch.ElapsedMilliseconds, dictionaryStopwatch.ElapsedMilliseconds)) + " milliseconds."); }
public void CuckooHash_Add_Remove_Lots_To_Test_Shrink() { CuckooHash <int, string> hash = new CuckooHash <int, string>(); int originalNumberOfStorageSlots = hash.StorageSlots; new IDictionaryTest().Add_Remove_Lots_To_Test_Shrink(hash); int newNumberOfStorageSlots = hash.StorageSlots; Assert.IsTrue(newNumberOfStorageSlots <= (originalNumberOfStorageSlots * 2)); }
public void CuckooHash_Compare_Dictionary_Insert_Speeds() { int howLarge = 20000; Stopwatch cuckooStopwatch = new Stopwatch(); CuckooHash <string, string> cuckooHash = new CuckooHash <string, string>(); cuckooStopwatch.Start(); new IDictionaryTest().Insert_Random(cuckooHash, howLarge); cuckooStopwatch.Stop(); Stopwatch dictionaryStopwatch = new Stopwatch(); Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionaryStopwatch.Start(); new IDictionaryTest().Insert_Random(dictionary, howLarge); dictionaryStopwatch.Stop(); Console.Out.WriteLine("Cuckoo hash took " + cuckooStopwatch.ElapsedMilliseconds + " milliseconds."); Console.Out.WriteLine("Dictionary took " + dictionaryStopwatch.ElapsedMilliseconds + " milliseconds."); Console.Out.WriteLine("Difference is " + (Math.Max(cuckooStopwatch.ElapsedMilliseconds, dictionaryStopwatch.ElapsedMilliseconds) - Math.Min(cuckooStopwatch.ElapsedMilliseconds, dictionaryStopwatch.ElapsedMilliseconds)) + " milliseconds."); }