##// END OF EJS Templates
sync
cin -
r108:f3bdb7ba59b9 v2
parent child
Show More
@@ -1,48 +1,79
1 using System;
1 using System;
2 using Implab.Diagnostics;
2 using Implab.Diagnostics;
3 using Implab.Parallels;
3 using Implab.Parallels;
4 using Implab;
4 using Implab;
5 using System.Collections.Generic;
5 using System.Collections.Generic;
6 using System.Collections.Concurrent;
6 using System.Collections.Concurrent;
7
7
8 namespace MonoPlay {
8 namespace MonoPlay {
9 class MainClass {
9 class MainClass {
10 public static void Main(string[] args) {
10 public static void Main(string[] args) {
11 if (args == null)
11 if (args == null)
12 throw new ArgumentNullException("args");
12 throw new ArgumentNullException("args");
13
13
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;
28
41
29 for (var i = 0; i < count; i++)
42 for (var i = 0; i < count; i++)
30 q2.Enqueue(i);
43 q2.Enqueue(i);
31
44
32 t2 = Environment.TickCount;
45 t2 = Environment.TickCount;
33 Console.WriteLine("LinkedList: {0} ms", t2 - t1);
46 Console.WriteLine("LinkedList: {0} ms", t2 - t1);
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 }
47 }
78 }
48 }
79 }
General Comments 0
You need to be logged in to leave comments. Login now