/// <summary> /// StringMap2 /// </summary> private static void benchmark8(int size) { GC.Collect(); var dictionary = new StringMap2<int>(); var keys = new string[size]; for (int i = 0; i < keys.Length; i++) keys[i] = i.ToString(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < keys.Length; i++) dictionary.Add(keys[(long)i * psrandmul % keys.Length], (int)(((long)i * psrandmul) % keys.Length)); sw.Stop(); Console.WriteLine(sw.Elapsed); GC.GetTotalMemory(true); sw.Restart(); int c = 0; foreach (var t in dictionary) { if (t.Key.Length != 0) c++; // System.Diagnostics.Debugger.Break(); // порядок не соблюдается. Проверка бессмыслена } if (c != dictionary.Count) System.Diagnostics.Debugger.Break(); sw.Stop(); Console.WriteLine(sw.Elapsed); GC.GetTotalMemory(true); sw.Restart(); c = 0; for (int i = 0; i < keys.Length; i++) { c++; if (dictionary[keys[i]] != i) throw new Exception(); } if (c != dictionary.Count) System.Diagnostics.Debugger.Break(); sw.Stop(); Console.WriteLine(sw.Elapsed); Console.WriteLine(dictionary.stat0); Console.WriteLine(dictionary.stat1); }
static void Main(string[] args) { //var primes = new StringBuilder(); //for (var i = 3; i < 10000000; i = getPrime(i + (i >> 2) + 3)) // primes.Append(i).Append(','); //var pv = primes.ToString(); //Console.WriteLine(pv); //Console.WriteLine(getPrime(21)); //return; if (false) { var sm2 = new StringMap2<string>(); sm2["0"] = "world"; sm2["1"] = "world1"; sm2["2"] = "world2"; sm2["3"] = "world3"; sm2["4"] = "world4"; sm2["5"] = "world5"; sm2["6"] = "world6"; sm2["7"] = "world7"; sm2["8"] = "world8"; Console.WriteLine(sm2["0"]); Console.WriteLine(sm2["1"]); Console.WriteLine(sm2["2"]); Console.WriteLine(sm2["3"]); Console.WriteLine(sm2["4"]); Console.WriteLine(sm2["5"]); Console.WriteLine(sm2["6"]); Console.WriteLine(sm2["7"]); Console.WriteLine(sm2["8"]); } else if (true) { for (var i = 0; i < 10000; i++) { var sm2 = new StringMap2<int>(); for (var j = 0; j < 10000; j++) sm2["test key " + j] = j; if (!sm2.Remove("test key " + i)) throw new Exception(); for (var j = 0; j < 10000; j++) { if (j == i) continue; else if (sm2["test key " + j] != j) throw new Exception(); } } } return; for (var i = 3; i-- > 0; ) { benchmark2(8000000); GC.Collect(0); GC.Collect(1); GC.Collect(2); GC.GetTotalMemory(true); benchmark8(8000000); Console.WriteLine("-------------------"); GC.Collect(0); GC.Collect(1); GC.Collect(2); GC.GetTotalMemory(true); } }