forked from near/borsh-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
92 lines (83 loc) · 1.35 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package borsh_test
import (
"math/rand"
"testing"
"github.com/eteu-technologies/borsh-go"
)
type B struct {
I8 int8
I16 int16
I32 int32
I64 int64
U8 uint8
U16 uint16
U32 uint32
U64 uint64
F32 float32
F64 float64
}
func BenchmarkDeserialize(t *testing.B) {
x := B{
I8: 12,
I16: -1,
I32: 124,
I64: 1243,
U8: 1,
U16: 979,
U32: 123124,
U64: 1135351135,
F32: -231.23,
F64: 3121221.232,
}
data, err := borsh.Serialize(x)
if err != nil {
t.Error(err)
}
y := new(B)
for i := 0; i < t.N; i++ {
err = borsh.Deserialize(y, data)
if err != nil {
t.Error(err)
}
}
}
func BenchmarkSerialize(t *testing.B) {
x := B{
I8: 12,
I16: -1,
I32: 124,
I64: 1243,
U8: 1,
U16: 979,
U32: 123124,
U64: 1135351135,
F32: -231.23,
F64: 3121221.232,
}
for i := 0; i < t.N; i++ {
_, _ = borsh.Serialize(x)
}
}
func BenchmarkFuzzSerialize(t *testing.B) {
s1 := rand.NewSource(42)
r1 := rand.New(s1)
for i := 0; i < 100; i++ {
st := fuzzType(r1, 0)
val := fuzzValue(r1, st)
for j := 0; j < t.N; j++ {
_, _ = borsh.Serialize(val)
}
}
}
func BenchmarkFuzzDeserialize(t *testing.B) {
s1 := rand.NewSource(42)
r1 := rand.New(s1)
for i := 0; i < 100; i++ {
st := fuzzType(r1, 0)
val := fuzzValue(r1, st)
data, _ := borsh.Serialize(val)
for j := 0; j < t.N; j++ {
_ = borsh.Deserialize(val, data)
}
}
}