public void Test() { m_wait = new ManualResetEvent(false); m_collection = new ConcurrentIsolatedQueue <Tuple <int> >(); ThreadPool.QueueUserWorkItem(RunTwo); m_wait.WaitOne(); m_wait.Reset(); Stopwatch sw = new Stopwatch(); sw.Start(); for (int x = 0; x < cnt; x++) { if (x % 10000 == 0) { System.Console.WriteLine(m_collection.Count); Thread.Sleep(1); } m_collection.Enqueue(new Tuple <int>(x)); } sw.Stop(); System.Console.WriteLine(sw.Elapsed.TotalSeconds); m_wait.WaitOne(); }
public void BenchmarkWrite() { string value = null; int x = 0; const int cnt = 10000; const int loop = 10000; List<string> items = new List<string>(cnt); for (x = 0; x < cnt; x++) { items.Add(x.ToString()); } var queue = new ConcurrentIsolatedQueue<string>(); Stopwatch swDequeue = new Stopwatch(); Stopwatch swEnqueue = new Stopwatch(); for (int repeat = 0; repeat < loop; repeat++) { swEnqueue.Start(); foreach (var item in items) queue.Enqueue(item); swEnqueue.Stop(); swDequeue.Start(); while (queue.TryDequeue(out value)) ; swDequeue.Stop(); } swEnqueue.Reset(); swDequeue.Reset(); for (int repeat = 0; repeat < loop; repeat++) { swEnqueue.Start(); foreach (var item in items) queue.Enqueue(item); swEnqueue.Stop(); swDequeue.Start(); while (queue.TryDequeue(out value)) ; swDequeue.Stop(); } System.Console.WriteLine("Enqueue " + (cnt * loop / swEnqueue.Elapsed.TotalSeconds / 1000000)); System.Console.WriteLine("Dequeue " + (cnt * loop / swDequeue.Elapsed.TotalSeconds / 1000000)); System.Console.WriteLine(swDequeue.Elapsed.TotalSeconds); }
public void TestCount() { m_collection = new ConcurrentIsolatedQueue <Tuple <int> >(); Tuple <int> value; long count = 0; for (int x = 0; x < 100000; x++) { if (m_collection.Count != count) { Assert.Fail("Count is wrong"); } m_collection.Enqueue(new Tuple <int>(x)); count++; if (x % 10 == 0) { m_collection.TryDequeue(out value); { count--; if (m_collection.Count != count) { Assert.Fail("Count is wrong"); } } } } while (m_collection.TryDequeue(out value)) { count--; if (m_collection.Count != count) { Assert.Fail("Count is wrong"); } } }
public void BenchmarkWrite() { string value = null; int x = 0; const int cnt = 10000; const int loop = 10000; List <string> items = new List <string>(cnt); for (x = 0; x < cnt; x++) { items.Add(x.ToString()); } var queue = new ConcurrentIsolatedQueue <string>(); Stopwatch swDequeue = new Stopwatch(); Stopwatch swEnqueue = new Stopwatch(); for (int repeat = 0; repeat < loop; repeat++) { swEnqueue.Start(); foreach (var item in items) { queue.Enqueue(item); } swEnqueue.Stop(); swDequeue.Start(); while (queue.TryDequeue(out value)) { ; } swDequeue.Stop(); } swEnqueue.Reset(); swDequeue.Reset(); for (int repeat = 0; repeat < loop; repeat++) { swEnqueue.Start(); foreach (var item in items) { queue.Enqueue(item); } swEnqueue.Stop(); swDequeue.Start(); while (queue.TryDequeue(out value)) { ; } swDequeue.Stop(); } System.Console.WriteLine("Enqueue " + (cnt * loop / swEnqueue.Elapsed.TotalSeconds / 1000000)); System.Console.WriteLine("Dequeue " + (cnt * loop / swDequeue.Elapsed.TotalSeconds / 1000000)); System.Console.WriteLine(swDequeue.Elapsed.TotalSeconds); }
public void TestCount() { m_collection = new ConcurrentIsolatedQueue<Tuple<int>>(); Tuple<int> value; long count = 0; for (int x = 0; x < 100000; x++) { if (m_collection.Count != count) Assert.Fail("Count is wrong"); m_collection.Enqueue(new Tuple<int>(x)); count++; if (x % 10 == 0) { m_collection.TryDequeue(out value); { count--; if (m_collection.Count != count) Assert.Fail("Count is wrong"); } } } while (m_collection.TryDequeue(out value)) { count--; if (m_collection.Count != count) Assert.Fail("Count is wrong"); } }
public void Test() { m_wait = new ManualResetEvent(false); m_collection = new ConcurrentIsolatedQueue<Tuple<int>>(); ThreadPool.QueueUserWorkItem(RunTwo); m_wait.WaitOne(); m_wait.Reset(); Stopwatch sw = new Stopwatch(); sw.Start(); for (int x = 0; x < cnt; x++) { if (x % 10000 == 0) { System.Console.WriteLine(m_collection.Count); Thread.Sleep(1); } m_collection.Enqueue(new Tuple<int>(x)); } sw.Stop(); System.Console.WriteLine(sw.Elapsed.TotalSeconds); m_wait.WaitOne(); }