##// END OF EJS Templates
sync
cin -
r108:f3bdb7ba59b9 v2
parent child
Show More
@@ -1,48 +1,79
1 1 using System;
2 2 using Implab.Diagnostics;
3 3 using Implab.Parallels;
4 4 using Implab;
5 5 using System.Collections.Generic;
6 6 using System.Collections.Concurrent;
7 7
8 8 namespace MonoPlay {
9 9 class MainClass {
10 10 public static void Main(string[] args) {
11 11 if (args == null)
12 12 throw new ArgumentNullException("args");
13 13
14 14 var q1 = new MTQueue<int>();
15 15 var q2 = new Queue<int>();
16 16
17 17 const int count = 10000000;
18 18
19
19 20 var t1 = Environment.TickCount;
20 21
22 Promise<int>.CreateComposite(
23 new [] {
24 AsyncPool.InvokeNewThread(() => {
21 25 for (var i = 0; i < count; i++)
22 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);
26 39
27 40 t1 = Environment.TickCount;
28 41
29 42 for (var i = 0; i < count; i++)
30 43 q2.Enqueue(i);
31 44
32 45 t2 = Environment.TickCount;
33 46 Console.WriteLine("LinkedList: {0} ms", t2 - t1);
34 47
35 48 q2 = new Queue<int>();
36 49
37 50 t1 = Environment.TickCount;
38 51
52 Promise<int>.CreateComposite(
53 new [] {
54 AsyncPool.InvokeNewThread(() => {
39 55 for (var i = 0; i < count; i++)
40 56 lock (q2)
41 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);
45 76
46 77 }
47 78 }
48 79 }
General Comments 0
You need to be logged in to leave comments. Login now