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 39 40 41 42 43 44 45 46 47 48 49
|
package example
import (
"io/ioutil"
"testing"
"git.sr.ht/~sircmpwn/go-bare"
"github.com/stretchr/testify/assert"
)
func BenchmarkMarshal(b *testing.B) {
person, _ := makeCustomer(b)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := bare.Marshal(person)
if err != nil {
panic(err)
}
}
}
func BenchmarkUnmarshal(b *testing.B) {
_, buf := makeCustomer(b)
var person Person
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := bare.Unmarshal(buf, &person)
if err != nil {
panic(err)
}
}
}
func makeCustomer(b *testing.B) (Person, []byte) {
buf, err := ioutil.ReadFile("customer.bin")
assert.Nil(b, err)
b.SetBytes(int64(len(buf)))
var person Person
err = bare.Unmarshal(buf, &person)
assert.Nil(b, err)
return person, buf
}
|