Mercurial > pub > ImplabNet
comparison MonoPlay/Program.cs @ 121:62d2f1e98c4e v2
working version of AsyncQueue and batch operations
tests
author | cin |
---|---|
date | Mon, 12 Jan 2015 18:19:41 +0300 |
parents | f1b897999260 |
children | 0c8685c8b56b |
comparison
equal
deleted
inserted
replaced
120:f1b897999260 | 121:62d2f1e98c4e |
---|---|
14 var q1 = new AsyncQueue<int>(); | 14 var q1 = new AsyncQueue<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 int res1 = 0, res2 = 0; |
20 var t1 = Environment.TickCount; | 20 var t1 = Environment.TickCount; |
21 | 21 |
22 AsyncPool.ThreadRun( | 22 AsyncPool.RunThread( |
23 () => { | 23 () => { |
24 for (var i = 0; i < count; i++) | 24 for (var i = 0; i < count; i++) |
25 q1.Enqueue(i); | 25 q1.Enqueue(1); |
26 Console.WriteLine("done writer #1: {0} ms", Environment.TickCount - t1); | |
26 }, | 27 }, |
27 () => { | 28 () => { |
28 for (var i = 0; i < count; i++) | 29 for (var i = 0; i < count; i++) |
29 q1.Enqueue(i); | 30 q1.Enqueue(2); |
31 Console.WriteLine("done writer #2: {0} ms", Environment.TickCount - t1); | |
30 }, | 32 }, |
31 () => { | 33 () => { |
32 int temp = 0; | 34 int temp = 0; |
33 int i = 0; | 35 int i = 0; |
34 while (i < count) | 36 while (i < count) |
35 if (q1.TryDequeue(out temp)) | 37 if (q1.TryDequeue(out temp)) { |
36 i++; | 38 i++; |
39 res1 += temp; | |
40 } | |
41 Console.WriteLine("done reader #1: {0} ms", Environment.TickCount - t1); | |
37 }, | 42 }, |
38 () => { | 43 () => { |
39 int temp = 0; | 44 int temp = 0; |
40 int i = 0; | 45 int i = 0; |
41 while (i < count) | 46 while (i < count) |
42 if (q1.TryDequeue(out temp)) | 47 if (q1.TryDequeue(out temp)) { |
43 i++; | 48 i++; |
49 res2 += temp; | |
50 } | |
51 Console.WriteLine("done reader #2: {0} ms", Environment.TickCount - t1); | |
44 } | 52 } |
45 ) | 53 ) |
46 .Combine() | 54 .Combine() |
47 .Join(); | 55 .Join(); |
56 | |
57 Console.WriteLine("done: {0} ms, summ#1: {1}, summ#2: {2}, total: {3}", Environment.TickCount - t1, res1, res2, res1 + res2); | |
48 | 58 |
49 var t2 = Environment.TickCount; | 59 var t2 = Environment.TickCount; |
50 Console.WriteLine("MTQueue: {0} ms", t2 - t1); | 60 Console.WriteLine("MTQueue: {0} ms", t2 - t1); |
51 | 61 |
52 t1 = Environment.TickCount; | 62 t1 = Environment.TickCount; |
63 q2 = new Queue<int>(); | 73 q2 = new Queue<int>(); |
64 | 74 |
65 t1 = Environment.TickCount; | 75 t1 = Environment.TickCount; |
66 | 76 |
67 | 77 |
68 AsyncPool.ThreadRun( | 78 AsyncPool.RunThread( |
69 () => { | 79 () => { |
70 for (var i = 0; i < count; i++) | 80 for (var i = 0; i < count; i++) |
71 lock (q2) | 81 lock (q2) |
72 q2.Enqueue(i); | 82 q2.Enqueue(i); |
73 }, | 83 }, |