aboutsummaryrefslogtreecommitdiff
path: root/src/ProtoBench
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-06-10 16:03:22 -0500
committerrogerk <devnull@localhost>2011-06-10 16:03:22 -0500
commitafe844bc95f8a0b2399315e618b636a6f32191dd (patch)
tree324e6b9a3c1c73622565548faa4e42a44642e24f /src/ProtoBench
parent2b86884659413efb1cbbcf7ebe22ef46a565b13d (diff)
downloadprotobuf-afe844bc95f8a0b2399315e618b636a6f32191dd.tar.gz
protobuf-afe844bc95f8a0b2399315e618b636a6f32191dd.tar.bz2
protobuf-afe844bc95f8a0b2399315e618b636a6f32191dd.zip
Added the JsonFormatWriter/Reader
Diffstat (limited to 'src/ProtoBench')
-rw-r--r--src/ProtoBench/Program.cs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/ProtoBench/Program.cs b/src/ProtoBench/Program.cs
index 9de071f5..2239fe08 100644
--- a/src/ProtoBench/Program.cs
+++ b/src/ProtoBench/Program.cs
@@ -39,6 +39,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
+using Google.ProtocolBuffers.Serialization;
using Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.ProtoBench
@@ -127,12 +128,25 @@ namespace Google.ProtocolBuffers.ProtoBench
inputData = inputData ?? File.ReadAllBytes(file);
MemoryStream inputStream = new MemoryStream(inputData);
ByteString inputString = ByteString.CopyFrom(inputData);
- IMessage sampleMessage =
- defaultMessage.WeakCreateBuilderForType().WeakMergeFrom(inputString, registry).WeakBuild();
+ 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();
+
+ //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));
+
+ //Deserializers
if (!FastTest) RunBenchmark("Deserialize from byte string", inputData.Length,
() => defaultMessage.WeakCreateBuilderForType()
.WeakMergeFrom(inputString, registry)
@@ -151,6 +165,10 @@ namespace Google.ProtocolBuffers.ProtoBench
CodedInputStream.CreateInstance(inputStream), registry)
.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());
+
Console.WriteLine();
return true;
}