comparison MonoPlay/Program.cs @ 103:b3f5bc613905 v2

sync
author cin
date Sat, 08 Nov 2014 10:02:47 +0300
parents a43745f81f10
children 5f10d54b45df
comparison
equal deleted inserted replaced
102:b4c4d65b7def 103:b3f5bc613905
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;
6 using System.Collections.Concurrent;
5 7
6 namespace MonoPlay { 8 namespace MonoPlay {
7 class MainClass { 9 class MainClass {
8 public static void Main(string[] args) { 10 public static void Main(string[] args) {
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>();
14 16
15 MTComponentContainer.AppContainer.Add(listener); 17 const int count = 10000000;
16 18
17 TraceLog.StartLogicalOperation("program"); 19 var t1 = Environment.TickCount;
18 20
19 TraceLog.StartLogicalOperation("async"); 21 for (var i = 0; i < count; i++)
20 AsyncPool.Invoke(() => { 22 q1.Enqueue(i);
21 TraceLog.TraceInformation("Hello async");
22 TraceLog.StartLogicalOperation("foo");
23 return 0;
24 })
25 .EndLogicalOperation()
26 .Join();
27 23
28 TraceLog.EndLogicalOperation(); 24 var t2 = Environment.TickCount;
25 Console.WriteLine("MTQueue: {0} ms", t2 - t1);
26
27 t1 = Environment.TickCount;
28
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>();
36
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 }
32 } 48 }