Debian Codegraph @

example/bench_test.go

raw symbols SCIP
1 package example
2
3 import (
4 "io/ioutil"
5 "testing"
6
7 "git.sr.ht/~sircmpwn/go-bare"
8 "github.com/stretchr/testify/assert"
9 )
10
11 func BenchmarkMarshal(b *testing.B) {
12 person, _ := makeCustomer(b)
13 b.ResetTimer()
14
15 for i := 0; i < b.N; i++ {
16 _, err := bare.Marshal(person)
17 if err != nil {
18 panic(err)
19 }
20 }
21
22 }
23
24 func BenchmarkUnmarshal(b *testing.B) {
25 _, buf := makeCustomer(b)
26 var person Person
27 b.ResetTimer()
28
29 for i := 0; i < b.N; i++ {
30 err := bare.Unmarshal(buf, &person)
31 if err != nil {
32 panic(err)
33 }
34 }
35
36 }
37
38 func makeCustomer(b *testing.B) (Person, []byte) {
39 buf, err := ioutil.ReadFile("customer.bin")
40 assert.Nil(b, err)
41
42 b.SetBytes(int64(len(buf)))
43
44 var person Person
45 err = bare.Unmarshal(buf, &person)
46 assert.Nil(b, err)
47
48 return person, buf
49 }