diff --git a/MonoPlay/Program.cs b/MonoPlay/Program.cs --- a/MonoPlay/Program.cs +++ b/MonoPlay/Program.cs @@ -16,10 +16,23 @@ namespace MonoPlay { const int count = 10000000; + var t1 = Environment.TickCount; - for (var i = 0; i < count; i++) - q1.Enqueue(i); + Promise.CreateComposite( + new [] { + AsyncPool.InvokeNewThread(() => { + for (var i = 0; i < count; i++) + q1.Enqueue(i); + }), + AsyncPool.InvokeNewThread(() => { + int temp = 0; + for(int i =0 ; i< count ; i++) + while(!q1.TryDequeue(out temp)){ + } + }) + } + ).Join(); var t2 = Environment.TickCount; Console.WriteLine("MTQueue: {0} ms", t2 - t1); @@ -36,9 +49,27 @@ namespace MonoPlay { t1 = Environment.TickCount; - for (var i = 0; i < count; i++) - lock (q2) - q2.Enqueue(i); + Promise.CreateComposite( + new [] { + AsyncPool.InvokeNewThread(() => { + for (var i = 0; i < count; i++) + lock (q2) + q2.Enqueue(i); + }), + AsyncPool.InvokeNewThread(() => { + for(int i = 0 ; i< count ;) + lock(q2) { + if(q2.Count == 0) + continue; + q2.Dequeue(); + i++; + } + + }) + } + ).Join(); + + t2 = Environment.TickCount; Console.WriteLine("LinkedList+Lock: {0} ms", t2 - t1);