@@ -16,10 +16,23 namespace MonoPlay { | |||
|
16 | 16 | |
|
17 | 17 | const int count = 10000000; |
|
18 | 18 | |
|
19 | ||
|
19 | 20 | var t1 = Environment.TickCount; |
|
20 | 21 | |
|
21 | for (var i = 0; i < count; i++) | |
|
22 |
|
|
|
22 | Promise<int>.CreateComposite( | |
|
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 | 37 | var t2 = Environment.TickCount; |
|
25 | 38 | Console.WriteLine("MTQueue: {0} ms", t2 - t1); |
@@ -36,9 +49,27 namespace MonoPlay { | |||
|
36 | 49 | |
|
37 | 50 | t1 = Environment.TickCount; |
|
38 | 51 | |
|
39 | for (var i = 0; i < count; i++) | |
|
40 |
|
|
|
41 | q2.Enqueue(i); | |
|
52 | Promise<int>.CreateComposite( | |
|
53 | new [] { | |
|
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 | 74 | t2 = Environment.TickCount; |
|
44 | 75 | Console.WriteLine("LinkedList+Lock: {0} ms", t2 - t1); |
General Comments 0
You need to be logged in to leave comments.
Login now