-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbase64_json_bench_test.go
73 lines (63 loc) · 1.37 KB
/
base64_json_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
package identity_test
import (
"testing"
"github.com/TankerHQ/identity-go/v3"
"github.com/iancoleman/orderedmap"
)
type benchStruct struct {
PublicSignatureKey string `json:"public_signature_key"`
PublicEncryptionKey string `json:"public_encryption_key"`
PrivateEncryptionKey string `json:"private_encryption_key"`
}
var (
benchStructValue = benchStruct{
PublicSignatureKey: "str",
PublicEncryptionKey: "str",
PrivateEncryptionKey: "str",
}
benchMap = map[string]string{
"public_signature_key": "str",
"public_encryption_key": "str",
"private_encryption_key": "str",
}
benchOrderedMap = func() *orderedmap.OrderedMap {
ordered := orderedmap.New()
for k, v := range benchMap {
ordered.Set(k, v)
}
return ordered
}()
benchVecs = []struct {
desc string
data interface{}
}{
{
desc: "Struct",
data: benchStructValue,
},
{
desc: "Map",
data: benchMap,
},
{
desc: "OrderedMap",
data: benchOrderedMap,
},
}
)
func BenchmarkEncode(b *testing.B) {
for _, vec := range benchVecs {
b.Run(vec.desc, func(b *testing.B) {
for i := 0; i < b.N; i++ {
identity.Encode(vec.data) //nolint: errcheck
}
})
}
}
func BenchmarkDecode(b *testing.B) {
encoded, _ := identity.Encode(benchStructValue)
into := make(map[string]interface{})
for i := 0; i < b.N; i++ {
identity.Decode(*encoded, &into) //nolint: errcheck
}
}