diff options
author | csharptest <roger@csharptest.net> | 2011-06-10 23:54:53 -0500 |
---|---|---|
committer | rogerk <devnull@localhost> | 2011-06-10 23:54:53 -0500 |
commit | 7fc785c1d463c4424cf3e3c8d7fbe796e0197b70 (patch) | |
tree | 1ea510abf9dbf61d709e26ba1845b944bb87b8ef /src/ProtoBench | |
parent | ea5fd37d1dbf8229e358d47095f93d362e73cc5d (diff) | |
download | protobuf-7fc785c1d463c4424cf3e3c8d7fbe796e0197b70.tar.gz protobuf-7fc785c1d463c4424cf3e3c8d7fbe796e0197b70.tar.bz2 protobuf-7fc785c1d463c4424cf3e3c8d7fbe796e0197b70.zip |
Reader/Writer implementations changed to use static factories
Diffstat (limited to 'src/ProtoBench')
-rw-r--r-- | src/ProtoBench/Program.cs | 49 | ||||
-rw-r--r-- | src/ProtoBench/ProtoBench.csproj | 24 |
2 files changed, 38 insertions, 35 deletions
diff --git a/src/ProtoBench/Program.cs b/src/ProtoBench/Program.cs index ec051310..23af195c 100644 --- a/src/ProtoBench/Program.cs +++ b/src/ProtoBench/Program.cs @@ -131,30 +131,40 @@ namespace Google.ProtocolBuffers.ProtoBench MemoryStream inputStream = new MemoryStream(inputData);
ByteString inputString = ByteString.CopyFrom(inputData);
IMessage sampleMessage = defaultMessage.WeakCreateBuilderForType().WeakMergeFrom(inputString, registry).WeakBuild();
-
- StringWriter temp = new StringWriter();
- new XmlFormatWriter(temp).WriteMessage(sampleMessage);
- string xmlMessageText = temp.ToString();
- temp = new StringWriter();
- new JsonFormatWriter(temp).WriteMessage(sampleMessage);
- string jsonMessageText = temp.ToString();
- byte[] jsonBytes /*no pun intended*/ = Encoding.UTF8.GetBytes(jsonMessageText);
+ byte[] jsonBytes, xmlBytes;/*no pun intended, well... maybe for xml*/
+ using (MemoryStream temp = new MemoryStream())
+ {
+ XmlFormatWriter.CreateInstance(temp).WriteMessage(sampleMessage);
+ xmlBytes = temp.ToArray();
+ }
+ using (MemoryStream temp = new MemoryStream())
+ {
+ JsonFormatWriter.CreateInstance(temp).WriteMessage(sampleMessage);
+ jsonBytes = temp.ToArray();
+ }
IDictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.Ordinal);
new DictionaryWriter(dictionary).WriteMessage(sampleMessage);
-
//Serializers
if(!FastTest) RunBenchmark("Serialize to byte string", inputData.Length, () => sampleMessage.ToByteString());
RunBenchmark("Serialize to byte array", inputData.Length, () => sampleMessage.ToByteArray());
if (!FastTest) RunBenchmark("Serialize to memory stream", inputData.Length,
() => sampleMessage.WriteTo(new MemoryStream()));
- 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 xml", xmlBytes.Length, () =>
+ {
+ XmlFormatWriter.CreateInstance(new MemoryStream(), Encoding.UTF8).WriteMessage(sampleMessage);
+ } );
+ RunBenchmark("Serialize to json", jsonBytes.Length, () =>
+ {
+ JsonFormatWriter.CreateInstance(new MemoryStream()).WriteMessage(sampleMessage);
+ });
+ RunBenchmark("Serialize to json via xml", jsonBytes.Length,
+ () =>
+ XmlFormatWriter.CreateInstance(JsonReaderWriterFactory.CreateJsonWriter(new MemoryStream(), Encoding.UTF8))
+ .SetOptions(XmlWriterOptions.OutputJsonTypes)
+ .WriteMessage(sampleMessage)
);
RunBenchmark("Serialize to dictionary", sampleMessage.SerializedSize, () => new DictionaryWriter().WriteMessage(sampleMessage));
@@ -179,12 +189,11 @@ namespace Google.ProtocolBuffers.ProtoBench .WeakBuild();
});
- 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 xml", xmlBytes.Length, () => XmlFormatReader.CreateInstance(xmlBytes).Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild());
+ RunBenchmark("Deserialize from json", jsonBytes.Length, () => JsonFormatReader.CreateInstance(jsonBytes).Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild());
+ RunBenchmark("Deserialize from json via xml", jsonBytes.Length,
+ () => XmlFormatReader.CreateInstance(JsonReaderWriterFactory.CreateJsonReader(jsonBytes, System.Xml.XmlDictionaryReaderQuotas.Max))
+ .SetOptions(XmlReaderOptions.ReadNestedArrays).Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild());
RunBenchmark("Deserialize from dictionary", sampleMessage.SerializedSize, () => new DictionaryReader(dictionary).Merge(defaultMessage.WeakCreateBuilderForType()).WeakBuild());
diff --git a/src/ProtoBench/ProtoBench.csproj b/src/ProtoBench/ProtoBench.csproj index b1d676af..7722f8d2 100644 --- a/src/ProtoBench/ProtoBench.csproj +++ b/src/ProtoBench/ProtoBench.csproj @@ -56,15 +56,9 @@ <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.Runtime.Serialization" />
+ <Reference Include="System.ServiceModel" />
+ <Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
@@ -105,11 +99,11 @@ </BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
-->
</Project>
\ No newline at end of file |