Added benchmark for Json via XML using JsonReaderWriterFactory
diff --git a/src/ProtoBench/Program.cs b/src/ProtoBench/Program.cs
index 34860f3..ec05131 100644
--- a/src/ProtoBench/Program.cs
+++ b/src/ProtoBench/Program.cs
@@ -38,6 +38,8 @@
 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 @@
                 temp = new StringWriter();

                 new JsonFormatWriter(temp).WriteMessage(sampleMessage);

                 string jsonMessageText = temp.ToString();

+                byte[] jsonBytes /*no pun intended*/ = Encoding.UTF8.GetBytes(jsonMessageText);

 

                 IDictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.Ordinal);

                 new DictionaryWriter(dictionary).WriteMessage(sampleMessage);

@@ -149,6 +152,11 @@
 

                 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 @@
 

                 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();

diff --git a/src/ProtoBench/ProtoBench.csproj b/src/ProtoBench/ProtoBench.csproj
index 74e3ef5..b1d676a 100644
--- a/src/ProtoBench/ProtoBench.csproj
+++ b/src/ProtoBench/ProtoBench.csproj
@@ -56,6 +56,15 @@
   <ItemGroup>

     <Reference Include="System" />

     <Reference Include="System.Data" />

+    <Reference Include="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">

+      <RequiredTargetFramework>3.0</RequiredTargetFramework>

+    </Reference>

+    <Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">

+      <RequiredTargetFramework>3.0</RequiredTargetFramework>

+    </Reference>

+    <Reference Include="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

+      <RequiredTargetFramework>3.5</RequiredTargetFramework>

+    </Reference>

     <Reference Include="System.Xml" />

   </ItemGroup>

   <ItemGroup>