@@ -28,7 +28,7 @@ import (
28
28
"google.golang.org/grpc/test/codec_perf"
29
29
)
30
30
31
- func setupBenchmarkProtoCodecInputs (b * testing. B , payloadBaseSize uint32 ) []proto.Message {
31
+ func setupBenchmarkProtoCodecInputs (payloadBaseSize uint32 ) []proto.Message {
32
32
payloadBase := make ([]byte , payloadBaseSize )
33
33
// arbitrary byte slices
34
34
payloadSuffixes := [][]byte {
@@ -59,23 +59,21 @@ func BenchmarkProtoCodec(b *testing.B) {
59
59
payloadBaseSizes = append (payloadBaseSizes , 1 << i )
60
60
}
61
61
// range of SetParallelism
62
- parallelisms := make ([]uint32 , 0 )
62
+ parallelisms := make ([]int , 0 )
63
63
for i := uint32 (0 ); i <= 16 ; i += 4 {
64
- parallelisms = append (parallelisms , 1 << i )
64
+ parallelisms = append (parallelisms , int ( 1 << i ) )
65
65
}
66
66
for _ , s := range payloadBaseSizes {
67
67
for _ , p := range parallelisms {
68
- func (parallelism int , payloadBaseSize uint32 ) {
69
- protoStructs := setupBenchmarkProtoCodecInputs (b , payloadBaseSize )
70
- name := fmt .Sprintf ("MinPayloadSize:%v/SetParallelism(%v)" , payloadBaseSize , parallelism )
71
- b .Run (name , func (b * testing.B ) {
72
- codec := & protoCodec {}
73
- b .SetParallelism (parallelism )
74
- b .RunParallel (func (pb * testing.PB ) {
75
- benchmarkProtoCodec (codec , protoStructs , pb , b )
76
- })
68
+ protoStructs := setupBenchmarkProtoCodecInputs (s )
69
+ name := fmt .Sprintf ("MinPayloadSize:%v/SetParallelism(%v)" , s , p )
70
+ b .Run (name , func (b * testing.B ) {
71
+ codec := & protoCodec {}
72
+ b .SetParallelism (p )
73
+ b .RunParallel (func (pb * testing.PB ) {
74
+ benchmarkProtoCodec (codec , protoStructs , pb , b )
77
75
})
78
- }( int ( p ), s )
76
+ })
79
77
}
80
78
}
81
79
}
@@ -94,7 +92,8 @@ func fastMarshalAndUnmarshal(protoCodec Codec, protoStruct proto.Message, b *tes
94
92
if err != nil {
95
93
b .Errorf ("protoCodec.Marshal(_) returned an error" )
96
94
}
97
- if err := protoCodec .Unmarshal (marshaledBytes , protoStruct ); err != nil {
95
+ res := codec_perf.Buffer {}
96
+ if err := protoCodec .Unmarshal (marshaledBytes , & res ); err != nil {
98
97
b .Errorf ("protoCodec.Unmarshal(_) returned an error" )
99
98
}
100
99
}
0 commit comments