Mercurial > pub > ImplabNet
comparison Implab.Playground/Program.cs @ 236:302ca905c19e v2
JsonReader optimizations
| author | cin |
|---|---|
| date | Tue, 21 Nov 2017 14:57:58 +0300 |
| parents | 8dd666e6b6bf |
| children | b00441e04738 |
comparison
equal
deleted
inserted
replaced
| 235:b49969a7043c | 236:302ca905c19e |
|---|---|
| 76 }*/ | 76 }*/ |
| 77 | 77 |
| 78 | 78 |
| 79 static void Main(string[] args) { | 79 static void Main(string[] args) { |
| 80 | 80 |
| 81 //var queue = new ConcurrentQueue<int>(); | 81 var t = Environment.TickCount; |
| 82 var queue = new AsyncQueue<int>(); | 82 using (var reader = JsonReader.Create("e:\\citylots.json")) { |
| 83 //var queue = new SimpleAsyncQueue<int>(); | 83 while (reader.Read()) { |
| 84 } | |
| 85 } | |
| 84 | 86 |
| 85 const int wBatch = 32; | 87 Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms"); |
| 86 const long wCount = 1000000; | |
| 87 const long total = wBatch * wCount * 3; | |
| 88 | |
| 89 long r1 = 0, r2 = 0, r3 = 0; | |
| 90 const int rBatch = 1000; | |
| 91 long read = 0; | |
| 92 | |
| 93 var t1 = Environment.TickCount; | |
| 94 | |
| 95 AsyncPool.RunThread( | |
| 96 () => { | |
| 97 var buffer = new int[wBatch]; | |
| 98 for (int i = 0; i < wBatch; i++) | |
| 99 buffer[i] = 1; | |
| 100 | |
| 101 for (int i = 0; i < wCount; i++) | |
| 102 EnqueueRange(queue, buffer, 0, wBatch); | |
| 103 Console.WriteLine("done writer #1: {0} ms", Environment.TickCount - t1); | |
| 104 }, | |
| 105 () => { | |
| 106 var buffer = new int[wBatch]; | |
| 107 for (int i = 0; i < wBatch; i++) | |
| 108 buffer[i] = 1; | |
| 109 | |
| 110 for (int i = 0; i < wCount; i++) | |
| 111 EnqueueRange(queue, buffer, 0, wBatch); | |
| 112 Console.WriteLine("done writer #2: {0} ms", Environment.TickCount - t1); | |
| 113 }, | |
| 114 () => { | |
| 115 var buffer = new int[wBatch]; | |
| 116 for (int i = 0; i < wBatch; i++) | |
| 117 buffer[i] = 1; | |
| 118 | |
| 119 for (int i = 0; i < wCount; i++) | |
| 120 EnqueueRange(queue, buffer, 0, wBatch); | |
| 121 Console.WriteLine("done writer #3: {0} ms", Environment.TickCount - t1); | |
| 122 }, | |
| 123 () => { | |
| 124 var buffer = new int[rBatch]; | |
| 125 | |
| 126 while (read < total) { | |
| 127 int actual; | |
| 128 if (TryDequeueRange(queue, buffer, 0, rBatch, out actual)) { | |
| 129 for (int i = 0; i < actual; i++) | |
| 130 r1 += buffer[i]; | |
| 131 Interlocked.Add(ref read, actual); | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 Console.WriteLine("done reader #1: {0} ms", Environment.TickCount - t1); | |
| 136 }/*, | |
| 137 () => { | |
| 138 var buffer = new int[rBatch]; | |
| 139 | |
| 140 while (read < total) { | |
| 141 int actual; | |
| 142 if (TryDequeueRange(queue, buffer, 0, rBatch, out actual)) { | |
| 143 for (int i = 0; i < actual; i++) | |
| 144 r2 += buffer[i]; | |
| 145 Interlocked.Add(ref read, actual); | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 Console.WriteLine("done reader #2: {0} ms", Environment.TickCount - t1); | |
| 150 }*//*, | |
| 151 () => { | |
| 152 var buffer = new int[rBatch]; | |
| 153 | |
| 154 while (read < total) { | |
| 155 int actual; | |
| 156 if (TryDequeueRange(queue, buffer, 0, rBatch, out actual)) { | |
| 157 for (int i = 0; i < actual; i++) | |
| 158 r3 += buffer[i]; | |
| 159 Interlocked.Add(ref read, actual); | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 Console.WriteLine("done reader #3: {0} ms", Environment.TickCount - t1); | |
| 164 }*/ | |
| 165 ) | |
| 166 .PromiseAll() | |
| 167 .Join(); | |
| 168 | |
| 169 | |
| 170 Console.WriteLine( | |
| 171 "done: {0} ms, summ#1: {1}, summ#2: {2}, total: {3}, count: {4}", | |
| 172 Environment.TickCount - t1, | |
| 173 r1, | |
| 174 r2, | |
| 175 r1 + r2 + r3, | |
| 176 total | |
| 177 ); | |
| 178 | 88 |
| 179 Console.WriteLine("done"); | 89 Console.WriteLine("done"); |
| 180 } | 90 } |
| 181 } | 91 } |
| 182 } | 92 } |
