Commit a3767341 authored by Jon Skeet's avatar Jon Skeet

Changed benchmark namespace and fixed enum issue

parent 79c72a99
...@@ -178,13 +178,13 @@ ...@@ -178,13 +178,13 @@
description="Runs all performance tests"> description="Runs all performance tests">
<exec program="${tools-protobench}" <exec program="${tools-protobench}"
workingdir="${testdata-dir}"> workingdir="${testdata-dir}">
<arg value="Google.ProtocolBuffers.BenchmarkProtos.Message1,ProtoBench" /> <arg value="Google.ProtocolBuffers.ProtoBench.Message1,ProtoBench" />
<arg value="benchmark_message1.dat" /> <arg value="benchmark_message1.dat" />
<arg value="Google.ProtocolBuffers.BenchmarkProtos.SpeedMessage1,ProtoBench" /> <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage1,ProtoBench" />
<arg value="benchmark_message1.dat" /> <arg value="benchmark_message1.dat" />
<arg value="Google.ProtocolBuffers.BenchmarkProtos.Message3,ProtoBench" /> <arg value="Google.ProtocolBuffers.ProtoBench.Message3,ProtoBench" />
<arg value="benchmark_message3.dat" /> <arg value="benchmark_message3.dat" />
<arg value="Google.ProtocolBuffers.BenchmarkProtos.SpeedMessage3,ProtoBench" /> <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage3,ProtoBench" />
<arg value="benchmark_message3.dat" /> <arg value="benchmark_message3.dat" />
</exec> </exec>
</target> </target>
......
import "google/protobuf/csharp_options.proto"; import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.BenchmarkProtos"; option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.ProtoBench";
option (google.protobuf.csharp_file_options).umbrella_classname = "BenchmarkProtoFile"; option (google.protobuf.csharp_file_options).umbrella_classname = "BenchmarkProtoFile";
package proto2.benchmark.v2_api; package proto2.benchmark.v2_api;
......
import "google/protobuf/csharp_options.proto"; import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.BenchmarkProtos"; option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.ProtoBench";
option (google.protobuf.csharp_file_options).umbrella_classname = "BenchmarkSpeedProtoFile"; option (google.protobuf.csharp_file_options).umbrella_classname = "BenchmarkSpeedProtoFile";
package proto2.benchmark.v2_api; package proto2.benchmark.v2_api;
......
This diff is collapsed.
This diff is collapsed.
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using Google.ProtocolBuffers;
namespace ProtoBench { namespace Google.ProtocolBuffers.ProtoBench
{
/// <summary> /// <summary>
/// Simple benchmarking of arbitrary messages. /// Simple benchmarking of arbitrary messages.
/// </summary> /// </summary>
...@@ -52,21 +52,22 @@ namespace ProtoBench { ...@@ -52,21 +52,22 @@ namespace ProtoBench {
Benchmark("Serialize to byte string", inputData.Length, () => sampleMessage.ToByteString()); Benchmark("Serialize to byte string", inputData.Length, () => sampleMessage.ToByteString());
Benchmark("Serialize to byte array", inputData.Length, () => sampleMessage.ToByteArray()); Benchmark("Serialize to byte array", inputData.Length, () => sampleMessage.ToByteArray());
Benchmark("Serialize to memory stream", inputData.Length, () => sampleMessage.WriteTo(new MemoryStream())); Benchmark("Serialize to memory stream", inputData.Length, () => sampleMessage.WriteTo(new MemoryStream()));
Benchmark("Deserialize from byte string", inputData.Length, () => Benchmark("Deserialize from byte string", inputData.Length,
defaultMessage.WeakCreateBuilderForType() () => defaultMessage.WeakCreateBuilderForType()
.WeakMergeFrom(inputString) .WeakMergeFrom(inputString)
.WeakBuild() .WeakBuild()
); );
Benchmark("Deserialize from byte array", inputData.Length, () => Benchmark("Deserialize from byte array", inputData.Length,
defaultMessage.WeakCreateBuilderForType() () => defaultMessage.WeakCreateBuilderForType()
.WeakMergeFrom(CodedInputStream.CreateInstance(inputData)) .WeakMergeFrom(CodedInputStream.CreateInstance(inputData))
.WeakBuild() .WeakBuild()
); );
Benchmark("Deserialize from memory stream", inputData.Length, () => Benchmark("Deserialize from memory stream", inputData.Length, () => {
inputStream.Position = 0;
defaultMessage.WeakCreateBuilderForType() defaultMessage.WeakCreateBuilderForType()
.WeakMergeFrom(CodedInputStream.CreateInstance(inputStream)) .WeakMergeFrom(CodedInputStream.CreateInstance(inputStream))
.WeakBuild() .WeakBuild();
); });
return true; return true;
} catch (Exception e) { } catch (Exception e) {
Console.Error.WriteLine("Error: {0}", e.Message); Console.Error.WriteLine("Error: {0}", e.Message);
...@@ -92,8 +93,8 @@ namespace ProtoBench { ...@@ -92,8 +93,8 @@ namespace ProtoBench {
iterations = (int) ((TargetTime.Ticks / (double)elapsed.Ticks) * iterations); iterations = (int) ((TargetTime.Ticks / (double)elapsed.Ticks) * iterations);
elapsed = TimeAction(action, iterations); elapsed = TimeAction(action, iterations);
Console.WriteLine("{0}: {1} iterations in {2:f3}s; {3:f3}MB/s", Console.WriteLine("{0}: {1} iterations in {2:f3}s; {3:f3}MB/s",
name, iterations, elapsed.TotalSeconds, name, iterations, elapsed.TotalSeconds,
(iterations * dataSize) / (elapsed.TotalSeconds * 1024 * 1024)); (iterations * dataSize) / (elapsed.TotalSeconds * 1024 * 1024));
} }
private static TimeSpan TimeAction(Action action, int iterations) { private static TimeSpan TimeAction(Action action, int iterations) {
...@@ -105,4 +106,4 @@ namespace ProtoBench { ...@@ -105,4 +106,4 @@ namespace ProtoBench {
return sw.Elapsed; return sw.Elapsed;
} }
} }
} }
\ No newline at end of file
using System; using System;
using System.IO; using System.IO;
using System.Reflection;
using Google.ProtocolBuffers;
namespace ProtoDump { namespace Google.ProtocolBuffers.ProtoDump
{
/// <summary> /// <summary>
/// Small utility to load a binary message and dump it in text form /// Small utility to load a binary message and dump it in text form
/// </summary> /// </summary>
...@@ -40,4 +39,4 @@ namespace ProtoDump { ...@@ -40,4 +39,4 @@ namespace ProtoDump {
} }
} }
} }
} }
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection;
using Google.ProtocolBuffers.Descriptors; using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers.ProtoMunge namespace Google.ProtocolBuffers.ProtoMunge
...@@ -143,7 +142,7 @@ namespace Google.ProtocolBuffers.ProtoMunge ...@@ -143,7 +142,7 @@ namespace Google.ProtocolBuffers.ProtoMunge
return BitConverter.ToInt32(data, 0); return BitConverter.ToInt32(data, 0);
} }
case FieldType.Enum: case FieldType.Enum:
return MungeEnum(fieldDescriptor, (int) value); return MungeEnum(fieldDescriptor, (EnumValueDescriptor) value);
default: default:
// TODO(jonskeet): Different exception? // TODO(jonskeet): Different exception?
throw new ArgumentException("Invalid field descriptor"); throw new ArgumentException("Invalid field descriptor");
...@@ -207,16 +206,16 @@ namespace Google.ProtocolBuffers.ProtoMunge ...@@ -207,16 +206,16 @@ namespace Google.ProtocolBuffers.ProtoMunge
return min + (ulong)(range * rng.NextDouble()); return min + (ulong)(range * rng.NextDouble());
} }
private static object MungeEnum(FieldDescriptor fieldDescriptor, int original) { private static object MungeEnum(FieldDescriptor fieldDescriptor, EnumValueDescriptor original) {
// Find all the values which get encoded to the same size as the current value, and pick one at random // Find all the values which get encoded to the same size as the current value, and pick one at random
int originalSize = CodedOutputStream.ComputeRawVarint32Size((uint)original); int originalSize = CodedOutputStream.ComputeRawVarint32Size((uint)original.Number);
List<EnumValueDescriptor> sameSizeValues = new List<EnumValueDescriptor> (); List<EnumValueDescriptor> sameSizeValues = new List<EnumValueDescriptor> ();
foreach (EnumValueDescriptor candidate in fieldDescriptor.EnumType.Values) { foreach (EnumValueDescriptor candidate in fieldDescriptor.EnumType.Values) {
if (CodedOutputStream.ComputeRawVarint32Size((uint)candidate.Number) == originalSize) { if (CodedOutputStream.ComputeRawVarint32Size((uint)candidate.Number) == originalSize) {
sameSizeValues.Add(candidate); sameSizeValues.Add(candidate);
} }
} }
return sameSizeValues[rng.Next(sameSizeValues.Count)].Number; return sameSizeValues[rng.Next(sameSizeValues.Count)];
} }
private static object MungeByteString(ByteString byteString) { private static object MungeByteString(ByteString byteString) {
......
...@@ -88,8 +88,9 @@ namespace Google.ProtocolBuffers { ...@@ -88,8 +88,9 @@ namespace Google.ProtocolBuffers {
/// <summary> /// <summary>
/// Gets an element of a repeated field. For value type fields /// Gets an element of a repeated field. For value type fields
/// including enums, the boxed value is returned. For embedded /// excluding enums, the boxed value is returned. For embedded
/// message fields, the sub-message is returned. /// message fields, the sub-message is returned. For enums, the
/// relevant EnumValueDescriptor is returned.
/// </summary> /// </summary>
/// <exception cref="ArgumentException">the field is not a repeated field, /// <exception cref="ArgumentException">the field is not a repeated field,
/// or it's not a field of this type</exception> /// or it's not a field of this type</exception>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment