From ea5fd37d1dbf8229e358d47095f93d362e73cc5d Mon Sep 17 00:00:00 2001 From: csharptest Date: Fri, 10 Jun 2011 19:02:35 -0500 Subject: Added benchmark for Json via XML using JsonReaderWriterFactory --- src/ProtoBench/Program.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/ProtoBench/Program.cs') diff --git a/src/ProtoBench/Program.cs b/src/ProtoBench/Program.cs index 34860f33..ec051310 100644 --- a/src/ProtoBench/Program.cs +++ b/src/ProtoBench/Program.cs @@ -38,6 +38,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Runtime.Serialization.Json; +using System.Text; using System.Threading; using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.TestProtos; @@ -136,6 +138,7 @@ namespace Google.ProtocolBuffers.ProtoBench temp = new StringWriter(); new JsonFormatWriter(temp).WriteMessage(sampleMessage); string jsonMessageText = temp.ToString(); + byte[] jsonBytes /*no pun intended*/ = Encoding.UTF8.GetBytes(jsonMessageText); IDictionary dictionary = new Dictionary(StringComparer.Ordinal); new DictionaryWriter(dictionary).WriteMessage(sampleMessage); @@ -149,6 +152,11 @@ namespace Google.ProtocolBuffers.ProtoBench RunBenchmark("Serialize to xml", xmlMessageText.Length, () => new XmlFormatWriter(new StringWriter()).WriteMessage(sampleMessage)); RunBenchmark("Serialize to json", jsonMessageText.Length, () => new JsonFormatWriter(new StringWriter()).WriteMessage(sampleMessage)); + RunBenchmark("Serialize to json via xml", jsonMessageText.Length, + () => new XmlFormatWriter(JsonReaderWriterFactory.CreateJsonWriter(new MemoryStream(), Encoding.UTF8)) + { Options = XmlWriterOptions.OutputJsonTypes }.WriteMessage(sampleMessage) + ); + RunBenchmark("Serialize to dictionary", sampleMessage.SerializedSize, () => new DictionaryWriter().WriteMessage(sampleMessage)); //Deserializers @@ -173,6 +181,11 @@ namespace Google.ProtocolBuffers.ProtoBench RunBenchmark("Deserialize from xml", xmlMessageText.Length, () => new XmlFormatReader(xmlMessageText).Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild()); RunBenchmark("Deserialize from json", jsonMessageText.Length, () => new JsonFormatReader(jsonMessageText).Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild()); + RunBenchmark("Deserialize from json via xml", jsonMessageText.Length, + () => new XmlFormatReader(JsonReaderWriterFactory.CreateJsonReader(jsonBytes, System.Xml.XmlDictionaryReaderQuotas.Max)) + { Options = XmlReaderOptions.ReadNestedArrays } + .Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild()); + RunBenchmark("Deserialize from dictionary", sampleMessage.SerializedSize, () => new DictionaryReader(dictionary).Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild()); Console.WriteLine(); -- cgit v1.2.3