private static void SingelThread_HashCompositeOnDisk() { Console.WriteLine("SingelThread_HashOnDisk"); var dict = new MMFDictionary<int, Person>("SingelThread_HashCompositeOnDisk", 100000); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < MaxCount; i++) { dict.Add(i, new Person() { Id = i, Name = "Name" + i }); Person p = null; if (!dict.TryGetValue(i,out p)) throw new Exception(); if (i/100000 == 0) { Console.WriteLine("Count: " + i); } } sw.Stop(); Console.WriteLine(sw.Elapsed); }
private static void Threaded_HashCompositeOnDisk() { Console.WriteLine("Threaded_HashOnDisk"); var dict = new MMFDictionary<string, Person>("Threaded_HashCompositeOnDisk", 100000); Console.WriteLine("Queuing {0} items to Thread Pool", MaxCount); Console.WriteLine("Queue to Thread Pool 0"); System.Collections.Generic.List<WaitHandle> handles = new System.Collections.Generic.List<WaitHandle>(); Stopwatch sw = Stopwatch.StartNew(); for (int iItem = 1; iItem < 20; iItem++) { ManualResetEvent mre = new ManualResetEvent(false); handles.Add(mre); ThreadPool.QueueUserWorkItem(d => { for (int i = 0; i < MaxCount / 20; i++) { string key = Guid.NewGuid().ToString(); dict.Add(key, new Person { Id = i, Name = "Name" + i }); Person p = null; if (!dict.TryGetValue(key,out p)) throw new Exception(); } mre.Set(); }, null); } Console.WriteLine("Waiting for Thread Pool to drain"); WaitHandle.WaitAll(handles.ToArray()); sw.Stop(); Console.WriteLine("Thread Pool has been drained (Event fired)"); Console.WriteLine(sw.Elapsed); }