comparison MonoPlay/Program.cs @ 120:f1b897999260 v2

improved asyncpool usability working on batch operations on asyncqueue
author cin
date Mon, 12 Jan 2015 05:19:52 +0300
parents 2573b562e328
children 62d2f1e98c4e
comparison
equal deleted inserted replaced
119:2573b562e328 120:f1b897999260
17 const int count = 10000000; 17 const int count = 10000000;
18 18
19 19
20 var t1 = Environment.TickCount; 20 var t1 = Environment.TickCount;
21 21
22 new [] { 22 AsyncPool.ThreadRun(
23 AsyncPool.InvokeNewThread(() => { 23 () => {
24 for (var i = 0; i < count; i++) 24 for (var i = 0; i < count; i++)
25 q1.Enqueue(i); 25 q1.Enqueue(i);
26 }), 26 },
27 AsyncPool.InvokeNewThread(() => { 27 () => {
28 for (var i = 0; i < count; i++) 28 for (var i = 0; i < count; i++)
29 q1.Enqueue(i); 29 q1.Enqueue(i);
30 }), 30 },
31 AsyncPool.InvokeNewThread(() => { 31 () => {
32 int temp = 0; 32 int temp = 0;
33 int i = 0; 33 int i = 0;
34 while (i < count) 34 while (i < count)
35 if (q1.TryDequeue(out temp)) 35 if (q1.TryDequeue(out temp))
36 i++; 36 i++;
37 }), 37 },
38 AsyncPool.InvokeNewThread(() => { 38 () => {
39 int temp = 0; 39 int temp = 0;
40 int i = 0; 40 int i = 0;
41 while (i < count) 41 while (i < count)
42 if (q1.TryDequeue(out temp)) 42 if (q1.TryDequeue(out temp))
43 i++; 43 i++;
44 }) 44 }
45 } 45 )
46 .Combine() 46 .Combine()
47 .Join(); 47 .Join();
48 48
49 var t2 = Environment.TickCount; 49 var t2 = Environment.TickCount;
50 Console.WriteLine("MTQueue: {0} ms", t2 - t1); 50 Console.WriteLine("MTQueue: {0} ms", t2 - t1);
63 q2 = new Queue<int>(); 63 q2 = new Queue<int>();
64 64
65 t1 = Environment.TickCount; 65 t1 = Environment.TickCount;
66 66
67 67
68 new [] { 68 AsyncPool.ThreadRun(
69 AsyncPool.InvokeNewThread(() => { 69 () => {
70 for (var i = 0; i < count; i++) 70 for (var i = 0; i < count; i++)
71 lock (q2) 71 lock (q2)
72 q2.Enqueue(i); 72 q2.Enqueue(i);
73 }), 73 },
74 AsyncPool.InvokeNewThread(() => { 74 () => {
75 for (var i = 0; i < count; i++) 75 for (var i = 0; i < count; i++)
76 lock (q2) 76 lock (q2)
77 q2.Enqueue(i); 77 q2.Enqueue(i);
78 }), 78 },
79 AsyncPool.InvokeNewThread(() => { 79 () => {
80 for (int i = 0; i < count ;) 80 for (int i = 0; i < count ;)
81 lock (q2) { 81 lock (q2) {
82 if (q2.Count == 0) 82 if (q2.Count == 0)
83 continue; 83 continue;
84 q2.Dequeue(); 84 q2.Dequeue();
85 i++; 85 i++;
86 } 86 }
87 87
88 }), 88 },
89 AsyncPool.InvokeNewThread(() => { 89 () => {
90 for (int i = 0; i < count ;) 90 for (int i = 0; i < count ;)
91 lock (q2) { 91 lock (q2) {
92 if (q2.Count == 0) 92 if (q2.Count == 0)
93 continue; 93 continue;
94 q2.Dequeue(); 94 q2.Dequeue();
95 i++; 95 i++;
96 } 96 }
97 97
98 }) 98 }
99 } 99 )
100 .Combine() 100 .Combine()
101 .Join(); 101 .Join();
102 102
103 103
104 104