Mercurial > pub > ImplabNet
comparison Implab.Format.Test/JsonTests.cs @ 236:302ca905c19e v2
JsonReader optimizations
author | cin |
---|---|
date | Tue, 21 Nov 2017 14:57:58 +0300 |
parents | 5f7a3e1d32b9 |
children |
comparison
equal
deleted
inserted
replaced
235:b49969a7043c | 236:302ca905c19e |
---|---|
8 using System.IO; | 8 using System.IO; |
9 | 9 |
10 namespace Implab.Format.Test { | 10 namespace Implab.Format.Test { |
11 [TestFixture] | 11 [TestFixture] |
12 public class JsonTests { | 12 public class JsonTests { |
13 | 13 |
14 [Test] | 14 [Test] |
15 public void TestScannerValidTokens() { | 15 public void TestScannerValidTokens() { |
16 using (var scanner = JsonStringScanner.Create(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:")) { | 16 using (var scanner = JsonStringScanner.Create(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:")) { |
17 | 17 |
18 Tuple<JsonTokenType, object>[] expexted = { | 18 Tuple<JsonTokenType, object>[] expexted = { |
112 DumpJsonParse("{\"one\":1, \"two\":2}"); | 112 DumpJsonParse("{\"one\":1, \"two\":2}"); |
113 DumpJsonParse("[1,\"\",2,3]"); | 113 DumpJsonParse("[1,\"\",2,3]"); |
114 DumpJsonParse("[{\"info\": [7,8,9]}]"); | 114 DumpJsonParse("[{\"info\": [7,8,9]}]"); |
115 DumpJsonFlatParse("[1,2,\"\",[3,4],{\"info\": [5,6]},{\"num\": [7,8,null]}, null,[null]]"); | 115 DumpJsonFlatParse("[1,2,\"\",[3,4],{\"info\": [5,6]},{\"num\": [7,8,null]}, null,[null]]"); |
116 } | 116 } |
117 | 117 |
118 [Test] | |
119 public void JsonBenchmark() { | |
120 var t = Environment.TickCount; | |
121 using (var reader = new JsonXmlReader(JsonReader.Create("e:\\citylots.json"), new JsonXmlReaderOptions { NamespaceUri = "XmlReaderSimpleTest", RootName = "data" })) { | |
122 while (reader.Read()) { | |
123 } | |
124 } | |
125 Console.WriteLine($"JsonXmlReader: {Environment.TickCount - t} ms"); | |
126 | |
127 t = Environment.TickCount; | |
128 using(var reader = JsonReader.Create("e:\\citylots.json")) { | |
129 while(reader.Read()) { | |
130 } | |
131 } | |
132 | |
133 Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms"); | |
134 | |
135 t = Environment.TickCount; | |
136 using (var reader = XmlReader.Create("file:///e:\\citylots.xml")) { | |
137 while (reader.Read()) { | |
138 } | |
139 } | |
140 | |
141 Console.WriteLine($"XmlReader: {Environment.TickCount - t} ms"); | |
142 } | |
143 | |
118 void AssertRead(XmlReader reader, XmlNodeType expected) { | 144 void AssertRead(XmlReader reader, XmlNodeType expected) { |
119 Assert.IsTrue(reader.Read()); | 145 Assert.IsTrue(reader.Read()); |
120 Console.WriteLine($"{new string(' ', reader.Depth*2)}{reader}"); | 146 Console.WriteLine($"{new string(' ', reader.Depth * 2)}{reader}"); |
121 Assert.AreEqual(expected, reader.NodeType); | 147 Assert.AreEqual(expected, reader.NodeType); |
122 } | 148 } |
123 | 149 |
124 void DumpJsonParse(string json) { | 150 void DumpJsonParse(string json) { |
125 Console.WriteLine($"JSON: {json}"); | 151 Console.WriteLine($"JSON: {json}"); |