comparison MonoPlay/Program.cs @ 108:f3bdb7ba59b9 v2

sync
author cin
date Tue, 11 Nov 2014 18:37:35 +0300
parents 5f10d54b45df
children 2573b562e328
comparison
equal deleted inserted replaced
107:f5220e5472ef 108:f3bdb7ba59b9
14 var q1 = new MTQueue<int>(); 14 var q1 = new MTQueue<int>();
15 var q2 = new Queue<int>(); 15 var q2 = new Queue<int>();
16 16
17 const int count = 10000000; 17 const int count = 10000000;
18 18
19
19 var t1 = Environment.TickCount; 20 var t1 = Environment.TickCount;
20 21
21 for (var i = 0; i < count; i++) 22 Promise<int>.CreateComposite(
22 q1.Enqueue(i); 23 new [] {
24 AsyncPool.InvokeNewThread(() => {
25 for (var i = 0; i < count; i++)
26 q1.Enqueue(i);
27 }),
28 AsyncPool.InvokeNewThread(() => {
29 int temp = 0;
30 for(int i =0 ; i< count ; i++)
31 while(!q1.TryDequeue(out temp)){
32 }
33 })
34 }
35 ).Join();
23 36
24 var t2 = Environment.TickCount; 37 var t2 = Environment.TickCount;
25 Console.WriteLine("MTQueue: {0} ms", t2 - t1); 38 Console.WriteLine("MTQueue: {0} ms", t2 - t1);
26 39
27 t1 = Environment.TickCount; 40 t1 = Environment.TickCount;
34 47
35 q2 = new Queue<int>(); 48 q2 = new Queue<int>();
36 49
37 t1 = Environment.TickCount; 50 t1 = Environment.TickCount;
38 51
39 for (var i = 0; i < count; i++) 52 Promise<int>.CreateComposite(
40 lock (q2) 53 new [] {
41 q2.Enqueue(i); 54 AsyncPool.InvokeNewThread(() => {
55 for (var i = 0; i < count; i++)
56 lock (q2)
57 q2.Enqueue(i);
58 }),
59 AsyncPool.InvokeNewThread(() => {
60 for(int i = 0 ; i< count ;)
61 lock(q2) {
62 if(q2.Count == 0)
63 continue;
64 q2.Dequeue();
65 i++;
66 }
67
68 })
69 }
70 ).Join();
71
72
42 73
43 t2 = Environment.TickCount; 74 t2 = Environment.TickCount;
44 Console.WriteLine("LinkedList+Lock: {0} ms", t2 - t1); 75 Console.WriteLine("LinkedList+Lock: {0} ms", t2 - t1);
45 76
46 } 77 }