mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-25 12:10:05 +00:00
93a04158fd
gvt fetch -a, because we need the protobuf files etc for regeneration
47 lines
932 B
Go
47 lines
932 B
Go
package proto_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
ppb "github.com/gogo/protobuf/proto/proto3_proto"
|
|
)
|
|
|
|
func marshalled() []byte {
|
|
m := &ppb.IntMaps{}
|
|
for i := 0; i < 1000; i++ {
|
|
m.Maps = append(m.Maps, &ppb.IntMap{
|
|
Rtt: map[int32]int32{1: 2},
|
|
})
|
|
}
|
|
b, err := proto.Marshal(m)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("Can't marshal %+v: %v", m, err))
|
|
}
|
|
return b
|
|
}
|
|
|
|
func BenchmarkConcurrentMapUnmarshal(b *testing.B) {
|
|
in := marshalled()
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
for pb.Next() {
|
|
var out ppb.IntMaps
|
|
if err := proto.Unmarshal(in, &out); err != nil {
|
|
b.Errorf("Can't unmarshal ppb.IntMaps: %v", err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkSequentialMapUnmarshal(b *testing.B) {
|
|
in := marshalled()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
var out ppb.IntMaps
|
|
if err := proto.Unmarshal(in, &out); err != nil {
|
|
b.Errorf("Can't unmarshal ppb.IntMaps: %v", err)
|
|
}
|
|
}
|
|
}
|