Commit a3767341 authored by Jon Skeet's avatar Jon Skeet

Changed benchmark namespace and fixed enum issue

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