Mercurial > pub > ImplabNet
diff Implab.Test/AsyncTests.cs @ 233:d6fe09f5592c v2
Improved AsyncQueue
Removed ImplabFx
author | cin |
---|---|
date | Wed, 04 Oct 2017 15:44:47 +0300 |
parents | 8200ab154c8a |
children |
line wrap: on
line diff
--- a/Implab.Test/AsyncTests.cs Tue Sep 12 19:07:42 2017 +0300 +++ b/Implab.Test/AsyncTests.cs Wed Oct 04 15:44:47 2017 +0300 @@ -222,9 +222,9 @@ [TestMethod] public void MTQueueTest() { - var queue = new MTQueue<int>(); + var queue = new SimpleAsyncQueue<int>(); int res; - + queue.Enqueue(10); Assert.IsTrue(queue.TryDequeue(out res)); Assert.AreEqual(10, res); @@ -242,8 +242,9 @@ int readers = 0; var stop = new ManualResetEvent(false); int total = 0; + var ticks = Environment.TickCount; - const int itemsPerWriter = 10000; + const int itemsPerWriter = 1000000; const int writersCount = 10; for (int i = 0; i < writersCount; i++) { @@ -278,7 +279,9 @@ stop.WaitOne(); - Assert.AreEqual(100000, total); + Console.WriteLine("{0} in {1}ms", total, Environment.TickCount - ticks); + + Assert.AreEqual(itemsPerWriter * writersCount, total); } [TestMethod] @@ -509,13 +512,12 @@ public void AsyncQueueDrainTest() { var queue = new AsyncQueue<int>(); - const int wBatch = 11; + const int wBatch = 32; const int wCount = 200000; const int total = wBatch * wCount * 3; const int summ = wBatch * wCount * 3; int r1 = 0, r2 = 0; - const int rBatch = 11; int read = 0; var t1 = Environment.TickCount; @@ -531,8 +533,12 @@ Console.WriteLine("done writer #1: {0} ms", Environment.TickCount - t1); }, () => { - for(int i =0; i < wCount * wBatch; i++) - queue.Enqueue(1); + var buffer = new int[wBatch]; + for (int i = 0; i < wBatch; i++) + buffer[i] = 1; + + for (int i = 0; i < wCount; i++) + queue.EnqueueRange(buffer, 0, wBatch); Console.WriteLine("done writer #2: {0} ms", Environment.TickCount - t1); }, () => { @@ -572,25 +578,34 @@ },*/ () => { var count = 0; - while(read < total) { + int emptyDrains = 0; + + while (read < total) { var buffer = queue.Drain(); - for(int i=0; i< buffer.Length; i++) + if (buffer.Count == 0) + emptyDrains++; + for(int i=0; i< buffer.Count; i++) r1 += buffer[i]; - Interlocked.Add(ref read, buffer.Length); - count += buffer.Length; + Interlocked.Add(ref read, buffer.Count); + count += buffer.Count; } - Console.WriteLine("done reader #1: {0} ms, {1} items", Environment.TickCount - t1, count); + Console.WriteLine("done reader #1: {0} ms, {1} items, empty: {2}", Environment.TickCount - t1, count, emptyDrains); }, () => { - var count = 0; - while(read < total) { + var count = 0; + int emptyDrains = 0; + + while (read < total) { var buffer = queue.Drain(); - for(int i=0; i< buffer.Length; i++) + if (buffer.Count == 0) + emptyDrains++; + + for (int i=0; i< buffer.Count; i++) r2 += buffer[i]; - Interlocked.Add(ref read, buffer.Length); - count += buffer.Length; + Interlocked.Add(ref read, buffer.Count); + count += buffer.Count; } - Console.WriteLine("done reader #2: {0} ms, {1} items", Environment.TickCount - t1, count); + Console.WriteLine("done reader #2: {0} ms, {1} items, empty: {2}", Environment.TickCount - t1, count, emptyDrains); } ) .PromiseAll()