1package proto_test
2
3import (
4	"fmt"
5	"testing"
6
7	"github.com/golang/protobuf/proto"
8	ppb "github.com/golang/protobuf/proto/proto3_proto"
9)
10
11func marshalled() []byte {
12	m := &ppb.IntMaps{}
13	for i := 0; i < 1000; i++ {
14		m.Maps = append(m.Maps, &ppb.IntMap{
15			Rtt: map[int32]int32{1: 2},
16		})
17	}
18	b, err := proto.Marshal(m)
19	if err != nil {
20		panic(fmt.Sprintf("Can't marshal %+v: %v", m, err))
21	}
22	return b
23}
24
25func BenchmarkConcurrentMapUnmarshal(b *testing.B) {
26	in := marshalled()
27	b.RunParallel(func(pb *testing.PB) {
28		for pb.Next() {
29			var out ppb.IntMaps
30			if err := proto.Unmarshal(in, &out); err != nil {
31				b.Errorf("Can't unmarshal ppb.IntMaps: %v", err)
32			}
33		}
34	})
35}
36
37func BenchmarkSequentialMapUnmarshal(b *testing.B) {
38	in := marshalled()
39	b.ResetTimer()
40	for i := 0; i < b.N; i++ {
41		var out ppb.IntMaps
42		if err := proto.Unmarshal(in, &out); err != nil {
43			b.Errorf("Can't unmarshal ppb.IntMaps: %v", err)
44		}
45	}
46}
47