-
Notifications
You must be signed in to change notification settings - Fork 15
/
bench_test.go
74 lines (68 loc) · 1.11 KB
/
bench_test.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package avro_test
import (
"context"
"testing"
qt "github.com/frankban/quicktest"
"github.com/heetch/avro"
)
func BenchmarkMarshal(b *testing.B) {
type R struct {
A *string
B *string
C []int
}
type T struct {
R R
}
x := T{
R: R{
A: newString("hello"),
B: newString("goodbye"),
C: []int{1, 3, 1 << 20},
},
}
for i := 0; i < b.N; i++ {
_, _, err := avro.Marshal(x)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkSingleDecoderUnmarshal(b *testing.B) {
c := qt.New(b)
type R struct {
A *string
B *string
C []int
}
type T struct {
R R
}
at, err := avro.TypeOf(T{})
c.Assert(err, qt.Equals, nil)
r := memRegistry{
1: at,
}
enc := avro.NewSingleEncoder(r, nil)
ctx := context.Background()
data, err := enc.Marshal(ctx, T{
R: R{
A: newString("hello"),
B: newString("goodbye"),
C: []int{1, 3, 1 << 20},
},
})
c.Assert(err, qt.Equals, nil)
dec := avro.NewSingleDecoder(r, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
var x T
_, err := dec.Unmarshal(ctx, data, &x)
if err != nil {
b.Fatal(err)
}
}
}
func newString(s string) *string {
return &s
}