93
|
1 using System;
|
|
2 using Implab.Diagnostics;
|
|
3 using Implab.Parallels;
|
|
4 using Implab;
|
103
|
5 using System.Collections.Generic;
|
|
6 using System.Collections.Concurrent;
|
93
|
7
|
|
8 namespace MonoPlay {
|
|
9 class MainClass {
|
|
10 public static void Main(string[] args) {
|
94
|
11 if (args == null)
|
|
12 throw new ArgumentNullException("args");
|
|
13
|
103
|
14 var q1 = new MTQueue<int>();
|
104
|
15 var q2 = new Queue<int>();
|
103
|
16
|
|
17 const int count = 10000000;
|
|
18
|
|
19 var t1 = Environment.TickCount;
|
93
|
20
|
103
|
21 for (var i = 0; i < count; i++)
|
|
22 q1.Enqueue(i);
|
93
|
23
|
103
|
24 var t2 = Environment.TickCount;
|
|
25 Console.WriteLine("MTQueue: {0} ms", t2 - t1);
|
|
26
|
|
27 t1 = Environment.TickCount;
|
93
|
28
|
103
|
29 for (var i = 0; i < count; i++)
|
|
30 q2.Enqueue(i);
|
|
31
|
|
32 t2 = Environment.TickCount;
|
|
33 Console.WriteLine("LinkedList: {0} ms", t2 - t1);
|
|
34
|
104
|
35 q2 = new Queue<int>();
|
93
|
36
|
103
|
37 t1 = Environment.TickCount;
|
|
38
|
|
39 for (var i = 0; i < count; i++)
|
|
40 lock (q2)
|
|
41 q2.Enqueue(i);
|
|
42
|
|
43 t2 = Environment.TickCount;
|
|
44 Console.WriteLine("LinkedList+Lock: {0} ms", t2 - t1);
|
93
|
45
|
|
46 }
|
|
47 }
|
|
48 }
|