diff Implab.Format.Test/JsonTests.cs @ 236:302ca905c19e v2

JsonReader optimizations
author cin
date Tue, 21 Nov 2017 14:57:58 +0300
parents 5f7a3e1d32b9
children
line wrap: on
line diff
--- a/Implab.Format.Test/JsonTests.cs	Thu Oct 05 09:24:49 2017 +0300
+++ b/Implab.Format.Test/JsonTests.cs	Tue Nov 21 14:57:58 2017 +0300
@@ -9,8 +9,8 @@
 
 namespace Implab.Format.Test {
     [TestFixture]
-    public class JsonTests {
-        
+    public class JsonTests {
+
         [Test]
         public void TestScannerValidTokens() {
             using (var scanner = JsonStringScanner.Create(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:")) {
@@ -114,10 +114,36 @@
             DumpJsonParse("[{\"info\": [7,8,9]}]");
             DumpJsonFlatParse("[1,2,\"\",[3,4],{\"info\": [5,6]},{\"num\": [7,8,null]}, null,[null]]");
         }
-        
+
+        [Test]
+        public void JsonBenchmark() {
+            var t = Environment.TickCount;
+            using (var reader = new JsonXmlReader(JsonReader.Create("e:\\citylots.json"), new JsonXmlReaderOptions { NamespaceUri = "XmlReaderSimpleTest", RootName = "data" })) {
+                while (reader.Read()) {
+                }
+            }
+            Console.WriteLine($"JsonXmlReader: {Environment.TickCount - t} ms");
+
+            t = Environment.TickCount;
+            using(var reader = JsonReader.Create("e:\\citylots.json")) {
+                while(reader.Read()) {
+                }
+            }
+
+            Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms");
+
+            t = Environment.TickCount;
+            using (var reader = XmlReader.Create("file:///e:\\citylots.xml")) {
+                while (reader.Read()) {
+                }
+            }
+
+            Console.WriteLine($"XmlReader: {Environment.TickCount - t} ms");
+        }
+
         void AssertRead(XmlReader reader, XmlNodeType expected) {
             Assert.IsTrue(reader.Read());
-            Console.WriteLine($"{new string(' ', reader.Depth*2)}{reader}");
+            Console.WriteLine($"{new string(' ', reader.Depth * 2)}{reader}");
             Assert.AreEqual(expected, reader.NodeType);
         }