@@ -27,7 +27,7 | |||||
27 | <OutputPath>bin\Release</OutputPath> |
|
27 | <OutputPath>bin\Release</OutputPath> | |
28 | <ErrorReport>prompt</ErrorReport> |
|
28 | <ErrorReport>prompt</ErrorReport> | |
29 | <WarningLevel>4</WarningLevel> |
|
29 | <WarningLevel>4</WarningLevel> | |
30 | <Externalconsole>true</Externalconsole> |
|
30 | <ConsolePause>false</ConsolePause> | |
31 | </PropertyGroup> |
|
31 | </PropertyGroup> | |
32 | <ItemGroup> |
|
32 | <ItemGroup> | |
33 | <Reference Include="System" /> |
|
33 | <Reference Include="System" /> |
@@ -2,6 +2,8 | |||||
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; | |||
|
6 | using System.Collections.Concurrent; | |||
5 |
|
7 | |||
6 | namespace MonoPlay { |
|
8 | namespace MonoPlay { | |
7 | class MainClass { |
|
9 | class MainClass { | |
@@ -9,23 +11,37 namespace MonoPlay { | |||||
9 | if (args == null) |
|
11 | if (args == null) | |
10 | throw new ArgumentNullException("args"); |
|
12 | throw new ArgumentNullException("args"); | |
11 |
|
13 | |||
12 | var listener = new ConsoleTraceListener(true); |
|
14 | var q1 = new MTQueue<int>(); | |
13 | listener.Subscribe<TraceEvent>(); |
|
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"); |
|
29 | for (var i = 0; i < count; i++) | |
20 | AsyncPool.Invoke(() => { |
|
30 | q2.Enqueue(i); | |
21 | TraceLog.TraceInformation("Hello async"); |
|
31 | ||
22 | TraceLog.StartLogicalOperation("foo"); |
|
32 | t2 = Environment.TickCount; | |
23 | return 0; |
|
33 | Console.WriteLine("LinkedList: {0} ms", t2 - t1); | |
24 | }) |
|
34 | ||
25 | .EndLogicalOperation() |
|
35 | q2 = new ConcurrentQueue<int>(); | |
26 | .Join(); |
|
|||
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