-
Notifications
You must be signed in to change notification settings - Fork 123
/
marshal_test.go
53 lines (43 loc) · 1.08 KB
/
marshal_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
// Copyright 2021-2023 Zenauth Ltd.
// SPDX-License-Identifier: Apache-2.0
package kafka
import (
"fmt"
"testing"
auditv1 "github.com/cerbos/cerbos/api/genpb/cerbos/audit/v1"
)
var encoding = []Encoding{EncodingJSON, EncodingProtobuf}
func BenchmarkRecordMarshaller_AccessLog(b *testing.B) {
for _, enc := range encoding {
b.Run(fmt.Sprintf("encoding_%s", enc), func(b *testing.B) {
m := newMarshaller(enc)
rec := &auditv1.AccessLogEntry{
CallId: "01ARZ3NDEKTSV4RRFFQ69G5FAV",
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := m.Marshal(rec, KindAccess); err != nil {
b.Fatal(err)
}
}
})
}
}
func BenchmarkRecordMarshaller_DecisionLog(b *testing.B) {
for _, enc := range encoding {
b.Run(fmt.Sprintf("encoding_%s", enc), func(b *testing.B) {
m := newMarshaller(enc)
rec := &auditv1.DecisionLogEntry{
CallId: "01ARZ3NDEKTSV4RRFFQ69G5FAV",
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := m.Marshal(rec, KindDecision); err != nil {
b.Fatal(err)
}
}
})
}
}