func BenchmarkVarint64ArrayMixed(b *testing.B) {
	for i := uint(1); i <= 1<<5; i <<= 1 {
		dist := genUint64Dist([11]int{0, 0, 0, 4, 6, 4, 0, 0, 0, 0, 0}, int(i))
		for k := uint(1); k <= 1<<10; k <<= 2 {
			msg := &tpb.Message{}
			for m := uint(0); m < k; m++ {
				msg.Children = append(msg.Children, &tpb.Message{
					Key: dist,
				})
			}
			raw, err := proto.Marshal(msg)
			if err != nil {
				b.Error("wrong encode", err)
			}
			b.Run(fmt.Sprintf("Fields%vLen%v", k, i), func(b *testing.B) {
				scratchBuf := proto.NewBuffer(nil)
				b.ResetTimer()
				for k := 0; k < b.N; k++ {
					scratchBuf.SetBuf(raw)
					msgBlackhole.Reset()
					if err := scratchBuf.Unmarshal(msgBlackhole); err != nil {
						b.Error("wrong decode", err)
					}
				}
			})
		}
	}
}
BenchmarkVarint64ArrayMixed shows the performance of lots of small messages, each
containing a small number of large (3, 4, and 5 byte) repeated int64s.
package proto_test
import (
	"fmt"
	"testing"
	"github.com/golang/protobuf/proto"
	tpb "github.com/golang/protobuf/proto/proto3_proto"
)
var (
	bytesBlackhole []byte
	msgBlackhole   = new(tpb.Message)
)
func BenchmarkVarint32ArraySmall(b *testing.B) {
	for i := uint(1); i <= 10; i++ {
		dist := genInt32Dist([7]int{0, 3, 1}, 1<<i)
		raw, err := proto.Marshal(&tpb.Message{
			ShortKey: dist,
		})
		if err != nil {
			b.Error("wrong encode", err)
		}
		b.Run(fmt.Sprintf("Len%v", len(dist)), func(b *testing.B) {
			scratchBuf := proto.NewBuffer(nil)
			b.ResetTimer()
			for k := 0; k < b.N; k++ {
				scratchBuf.SetBuf(raw)
				msgBlackhole.Reset()
				if err := scratchBuf.Unmarshal(msgBlackhole); err != nil {
					b.Error("wrong decode", err)
				}
			}
		})
	}
}
func BenchmarkVarint32ArrayLarge(b *testing.B) {
	for i := uint(1); i <= 10; i++ {
		dist := genInt32Dist([7]int{0, 1, 2, 4, 8, 1, 1}, 1<<i)
		raw, err := proto.Marshal(&tpb.Message{
			ShortKey: dist,
		})
		if err != nil {
			b.Error("wrong encode", err)
		}
		b.Run(fmt.Sprintf("Len%v", len(dist)), func(b *testing.B) {
			scratchBuf := proto.NewBuffer(nil)
			b.ResetTimer()
			for k := 0; k < b.N; k++ {
				scratchBuf.SetBuf(raw)
				msgBlackhole.Reset()
				if err := scratchBuf.Unmarshal(msgBlackhole); err != nil {
					b.Error("wrong decode", err)
				}
			}
		})
	}
}
func BenchmarkVarint64ArraySmall(b *testing.B) {
	for i := uint(1); i <= 10; i++ {
		dist := genUint64Dist([11]int{0, 3, 1}, 1<<i)
		raw, err := proto.Marshal(&tpb.Message{
			Key: dist,
		})
		if err != nil {
			b.Error("wrong encode", err)
		}
		b.Run(fmt.Sprintf("Len%v", len(dist)), func(b *testing.B) {
			scratchBuf := proto.NewBuffer(nil)
			b.ResetTimer()
			for k := 0; k < b.N; k++ {
				scratchBuf.SetBuf(raw)
				msgBlackhole.Reset()
				if err := scratchBuf.Unmarshal(msgBlackhole); err != nil {
					b.Error("wrong decode", err)
				}
			}
		})
	}
}
func BenchmarkVarint64ArrayLarge(b *testing.B) {
	for i := uint(1); i <= 10; i++ {
		dist := genUint64Dist([11]int{0, 1, 1, 2, 4, 8, 16, 32, 16, 1, 1}, 1<<i)
		raw, err := proto.Marshal(&tpb.Message{
			Key: dist,
		})
		if err != nil {
			b.Error("wrong encode", err)
		}
		b.Run(fmt.Sprintf("Len%v", len(dist)), func(b *testing.B) {
			scratchBuf := proto.NewBuffer(nil)
			b.ResetTimer()
			for k := 0; k < b.N; k++ {
				scratchBuf.SetBuf(raw)
				msgBlackhole.Reset()
				if err := scratchBuf.Unmarshal(msgBlackhole); err != nil {
					b.Error("wrong decode", err)
				}
			}
		})
	}
}