Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
a3767341
Commit
a3767341
authored
Jan 16, 2009
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed benchmark namespace and fixed enum issue
parent
79c72a99
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
36 additions
and
34 deletions
+36
-34
ProtocolBuffers.build
ProtocolBuffers.build
+4
-4
benchmark.proto
protos/google/protobuf/benchmark.proto
+1
-1
benchmark_speed.proto
protos/google/protobuf/benchmark_speed.proto
+1
-1
BenchmarkProtoFile.cs
src/ProtoBench/BenchmarkProtoFile.cs
+0
-0
BenchmarkSpeedProtoFile.cs
src/ProtoBench/BenchmarkSpeedProtoFile.cs
+0
-0
Program.cs
src/ProtoBench/Program.cs
+19
-17
Program.cs
src/ProtoDump/Program.cs
+4
-4
Program.cs
src/ProtoMunge/Program.cs
+4
-5
IMessage.cs
src/ProtocolBuffers/IMessage.cs
+3
-2
No files found.
ProtocolBuffers.build
View file @
a3767341
...
@@ -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>
...
...
protos/google/protobuf/benchmark.proto
View file @
a3767341
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
;
...
...
protos/google/protobuf/benchmark_speed.proto
View file @
a3767341
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
;
...
...
src/ProtoBench/BenchmarkProtoFile.cs
View file @
a3767341
This diff is collapsed.
Click to expand it.
src/ProtoBench/BenchmarkSpeedProtoFile.cs
View file @
a3767341
This diff is collapsed.
Click to expand it.
src/ProtoBench/Program.cs
View file @
a3767341
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
src/ProtoDump/Program.cs
View file @
a3767341
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
src/ProtoMunge/Program.cs
View file @
a3767341
...
@@ -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
)
{
...
...
src/ProtocolBuffers/IMessage.cs
View file @
a3767341
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment