@@ -27,7 +27,7 | |||
|
27 | 27 | <OutputPath>bin\Release</OutputPath> |
|
28 | 28 | <ErrorReport>prompt</ErrorReport> |
|
29 | 29 | <WarningLevel>4</WarningLevel> |
|
30 | <Externalconsole>true</Externalconsole> | |
|
30 | <ConsolePause>false</ConsolePause> | |
|
31 | 31 | </PropertyGroup> |
|
32 | 32 | <ItemGroup> |
|
33 | 33 | <Reference Include="System" /> |
@@ -2,6 +2,8 | |||
|
2 | 2 | using Implab.Diagnostics; |
|
3 | 3 | using Implab.Parallels; |
|
4 | 4 | using Implab; |
|
5 | using System.Collections.Generic; | |
|
6 | using System.Collections.Concurrent; | |
|
5 | 7 | |
|
6 | 8 | namespace MonoPlay { |
|
7 | 9 | class MainClass { |
@@ -9,23 +11,37 namespace MonoPlay { | |||
|
9 | 11 | if (args == null) |
|
10 | 12 | throw new ArgumentNullException("args"); |
|
11 | 13 | |
|
12 | var listener = new ConsoleTraceListener(true); | |
|
13 | listener.Subscribe<TraceEvent>(); | |
|
14 | var q1 = new MTQueue<int>(); | |
|
15 | var q2 = new ConcurrentQueue<int>(); | |
|
16 | ||
|
17 | const int count = 10000000; | |
|
18 | ||
|
19 | var t1 = Environment.TickCount; | |
|
14 | 20 | |
|
15 | MTComponentContainer.AppContainer.Add(listener); | |
|
21 | for (var i = 0; i < count; i++) | |
|
22 | q1.Enqueue(i); | |
|
16 | 23 | |
|
17 | TraceLog.StartLogicalOperation("program"); | |
|
24 | var t2 = Environment.TickCount; | |
|
25 | Console.WriteLine("MTQueue: {0} ms", t2 - t1); | |
|
26 | ||
|
27 | t1 = Environment.TickCount; | |
|
18 | 28 | |
|
19 | TraceLog.StartLogicalOperation("async"); | |
|
20 | AsyncPool.Invoke(() => { | |
|
21 | TraceLog.TraceInformation("Hello async"); | |
|
22 | TraceLog.StartLogicalOperation("foo"); | |
|
23 | return 0; | |
|
24 | }) | |
|
25 | .EndLogicalOperation() | |
|
26 | .Join(); | |
|
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 | ||
|
35 | q2 = new ConcurrentQueue<int>(); | |
|
27 | 36 | |
|
28 | TraceLog.EndLogicalOperation(); | |
|
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); | |
|
29 | 45 | |
|
30 | 46 | } |
|
31 | 47 | } |
General Comments 0
You need to be logged in to leave comments.
Login now