Mercurial > pub > ImplabNet
diff Implab.Test/AsyncTests.cs @ 16:5a4b735ba669 promises
sync
author | cin |
---|---|
date | Thu, 07 Nov 2013 20:20:26 +0400 |
parents | 0f982f9b7d4d |
children | 7cd4a843b4e4 |
line wrap: on
line diff
--- a/Implab.Test/AsyncTests.cs Thu Nov 07 03:41:32 2013 +0400 +++ b/Implab.Test/AsyncTests.cs Thu Nov 07 20:20:26 2013 +0400 @@ -242,6 +242,38 @@ } [TestMethod] + public void ChainedMapTest() { + + using (var pool = new WorkerPool(1,10)) { + int count = 10000; + + double[] args = new double[count]; + var rand = new Random(); + + for (int i = 0; i < count; i++) + args[i] = rand.NextDouble(); + + var t = Environment.TickCount; + var res = args + .ChainedMap( + x => pool.Invoke( + () => Math.Sin(x * x) + ), + 4 + ) + .Join(); + + Console.WriteLine("Map complete in {0} ms", Environment.TickCount - t); + + t = Environment.TickCount; + for (int i = 0; i < count; i++) + Assert.AreEqual(Math.Sin(args[i] * args[i]), res[i]); + Console.WriteLine("Verified in {0} ms", Environment.TickCount - t); + Console.WriteLine("Max workers: {0}", pool.MaxRunningThreads); + } + } + + [TestMethod] public void ParallelForEachTest() { int count = 100000;