forked from hamba/avro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench_embedded_test.go
More file actions
70 lines (51 loc) · 1.46 KB
/
Copy pathbench_embedded_test.go
File metadata and controls
70 lines (51 loc) · 1.46 KB
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
package avro_test
import (
"testing"
"github.com/iskorotkov/avro/v2"
)
type embedInner struct {
A int64 `avro:"a"`
B string `avro:"b"`
}
type embeddedValRecord struct {
C string `avro:"c"`
embedInner
}
type embeddedPtrRecord struct {
C string `avro:"c"`
*embedInner
}
const embeddedRecordSchema = `{"type":"record","name":"test","fields":[{"name":"a","type":"long"},{"name":"b","type":"string"},{"name":"c","type":"string"}]}`
var embeddedRecordData = []byte{0x36, 0x06, 0x66, 0x6f, 0x6f, 0x06, 0x62, 0x61, 0x72}
func BenchmarkEmbeddedValDecode(b *testing.B) {
schema := avro.MustParse(embeddedRecordSchema)
got := &embeddedValRecord{}
b.ReportAllocs()
for b.Loop() {
_ = avro.Unmarshal(schema, embeddedRecordData, got)
}
}
func BenchmarkEmbeddedPtrDecode(b *testing.B) {
schema := avro.MustParse(embeddedRecordSchema)
got := &embeddedPtrRecord{embedInner: &embedInner{}}
b.ReportAllocs()
for b.Loop() {
_ = avro.Unmarshal(schema, embeddedRecordData, got)
}
}
func BenchmarkEmbeddedValEncode(b *testing.B) {
schema := avro.MustParse(embeddedRecordSchema)
rec := &embeddedValRecord{C: "bar", embedInner: embedInner{A: 27, B: "foo"}}
b.ReportAllocs()
for b.Loop() {
_, _ = avro.Marshal(schema, rec)
}
}
func BenchmarkEmbeddedPtrEncode(b *testing.B) {
schema := avro.MustParse(embeddedRecordSchema)
rec := &embeddedPtrRecord{C: "bar", embedInner: &embedInner{A: 27, B: "foo"}}
b.ReportAllocs()
for b.Loop() {
_, _ = avro.Marshal(schema, rec)
}
}