File: uint32_test.go

package info (click to toggle)
golang-gogoprotobuf 1.0.0%2Bgit20180330.1ef32a8b-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,932 kB
  • sloc: makefile: 462; sh: 23
file content (38 lines) | stat: -rw-r--r-- 845 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package io_test

import (
	"encoding/binary"
	"io/ioutil"
	"math/rand"
	"testing"
	"time"

	"github.com/gogo/protobuf/test"
	example "github.com/gogo/protobuf/test/example"

	"github.com/gogo/protobuf/io"
)

func BenchmarkUint32DelimWriterMarshaller(b *testing.B) {
	w := io.NewUint32DelimitedWriter(ioutil.Discard, binary.BigEndian)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	msg := example.NewPopulatedA(r, true)

	for i := 0; i < b.N; i++ {
		if err := w.WriteMsg(msg); err != nil {
			b.Fatal(err)
		}
	}
}

func BenchmarkUint32DelimWriterFallback(b *testing.B) {
	w := io.NewUint32DelimitedWriter(ioutil.Discard, binary.BigEndian)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	msg := test.NewPopulatedNinOptNative(r, true)

	for i := 0; i < b.N; i++ {
		if err := w.WriteMsg(msg); err != nil {
			b.Fatal(err)
		}
	}
}