diff Implab.Playground/Program.cs @ 236:302ca905c19e v2

JsonReader optimizations
author cin
date Tue, 21 Nov 2017 14:57:58 +0300
parents 8dd666e6b6bf
children b00441e04738
line wrap: on
line diff
--- a/Implab.Playground/Program.cs	Thu Oct 05 09:24:49 2017 +0300
+++ b/Implab.Playground/Program.cs	Tue Nov 21 14:57:58 2017 +0300
@@ -78,103 +78,13 @@
 
         static void Main(string[] args) {
 
-            //var queue = new ConcurrentQueue<int>();
-            var queue = new AsyncQueue<int>();
-            //var queue = new SimpleAsyncQueue<int>();
-
-            const int wBatch = 32;
-            const long wCount = 1000000;
-            const long total = wBatch * wCount * 3;
-
-            long r1 = 0, r2 = 0, r3 = 0;
-            const int rBatch = 1000;
-            long read = 0;
-
-            var t1 = Environment.TickCount;
-
-            AsyncPool.RunThread(
-                () => {
-                    var buffer = new int[wBatch];
-                    for (int i = 0; i < wBatch; i++)
-                        buffer[i] = 1;
-
-                    for (int i = 0; i < wCount; i++)
-                        EnqueueRange(queue, buffer, 0, wBatch);
-                    Console.WriteLine("done writer #1: {0} ms", Environment.TickCount - t1);
-                },
-                () => {
-                    var buffer = new int[wBatch];
-                    for (int i = 0; i < wBatch; i++)
-                        buffer[i] = 1;
-
-                    for (int i = 0; i < wCount; i++)
-                        EnqueueRange(queue, buffer, 0, wBatch);
-                    Console.WriteLine("done writer #2: {0} ms", Environment.TickCount - t1);
-                },
-                () => {
-                    var buffer = new int[wBatch];
-                    for (int i = 0; i < wBatch; i++)
-                        buffer[i] = 1;
-
-                    for (int i = 0; i < wCount; i++)
-                        EnqueueRange(queue, buffer, 0, wBatch);
-                    Console.WriteLine("done writer #3: {0} ms", Environment.TickCount - t1);
-                },
-                () => {
-                    var buffer = new int[rBatch];
-
-                    while (read < total) {
-                        int actual;
-                        if (TryDequeueRange(queue, buffer, 0, rBatch, out actual)) {
-                            for (int i = 0; i < actual; i++)
-                                r1 += buffer[i];
-                            Interlocked.Add(ref read, actual);
-                        }
-                    }
-
-                    Console.WriteLine("done reader #1: {0} ms", Environment.TickCount - t1);
-                }/*,
-                () => {
-                    var buffer = new int[rBatch];
-
-                    while (read < total) {
-                        int actual;
-                        if (TryDequeueRange(queue, buffer, 0, rBatch, out actual)) {
-                            for (int i = 0; i < actual; i++)
-                                r2 += buffer[i];
-                            Interlocked.Add(ref read, actual);
-                        }
-                    }
-
-                    Console.WriteLine("done reader #2: {0} ms", Environment.TickCount - t1);
-                }*//*,
-                () => {
-                    var buffer = new int[rBatch];
-
-                    while (read < total) {
-                        int actual;
-                        if (TryDequeueRange(queue, buffer, 0, rBatch, out actual)) {
-                            for (int i = 0; i < actual; i++)
-                                r3 += buffer[i];
-                            Interlocked.Add(ref read, actual);
-                        }
-                    }
-
-                    Console.WriteLine("done reader #3: {0} ms", Environment.TickCount - t1);
-                }*/
-            )
-                .PromiseAll()
-                .Join();
-
-
-            Console.WriteLine(
-                "done: {0} ms, summ#1: {1}, summ#2: {2}, total: {3}, count: {4}",
-                Environment.TickCount - t1,
-                r1,
-                r2,
-                r1 + r2 + r3,
-                total
-            );
+            var t = Environment.TickCount;
+            using (var reader = JsonReader.Create("e:\\citylots.json")) {
+                while (reader.Read()) {
+                }
+            }
+
+            Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms");
 
             Console.WriteLine("done");
         }