forked from couchbase/gocbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurdcomponent_crud_bench_test.go
150 lines (124 loc) · 2.81 KB
/
curdcomponent_crud_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package gocbcore
import (
"fmt"
"github.com/google/uuid"
"sync/atomic"
"testing"
)
func BenchmarkSet(b *testing.B) {
b.ReportAllocs()
suite := GetBenchSuite()
agent := suite.GetAgent()
key := []byte(uuid.New().String())
// Generate 256 bytes of random data for the document
randomBytes := make([]byte, 256)
for i := 0; i < len(randomBytes); i++ {
randomBytes[i] = byte(i)
}
var i uint32
suite.RunParallel(b, func(cb func(error)) error {
keyNum := atomic.AddUint32(&i, 1)
_, err := agent.Set(SetOptions{
Key: []byte(fmt.Sprintf("%s-%d", key, keyNum)),
Value: randomBytes,
}, func(result *StoreResult, err error) {
cb(err)
})
return err
})
}
func BenchmarkReplace(b *testing.B) {
b.ReportAllocs()
suite := GetBenchSuite()
agent, s := suite.GetAgentAndHarness(b)
key := []byte(uuid.New().String())
s.PushOp(agent.Set(SetOptions{
Key: key,
Value: []byte("{}"),
}, func(result *StoreResult, err error) {
s.Wrap(func() {
if err != nil {
s.Fatalf("Failed to set: %v", err)
}
})
}))
s.Wait(0)
// Generate 256 bytes of random data for the document
randomBytes := make([]byte, 256)
for i := 0; i < len(randomBytes); i++ {
randomBytes[i] = byte(i)
}
suite.RunParallel(b, func(cb func(error)) error {
_, err := agent.Replace(ReplaceOptions{
Key: key,
Value: randomBytes,
}, func(result *StoreResult, err error) {
cb(err)
})
return err
})
}
func BenchmarkGet(b *testing.B) {
b.ReportAllocs()
suite := GetBenchSuite()
agent, s := suite.GetAgentAndHarness(b)
key := []byte(uuid.New().String())
// Generate 256 bytes of random data for the document
randomBytes := make([]byte, 256)
for i := 0; i < len(randomBytes); i++ {
randomBytes[i] = byte(i)
}
s.PushOp(agent.Set(SetOptions{
Key: key,
Value: randomBytes,
}, func(result *StoreResult, err error) {
s.Wrap(func() {
if err != nil {
s.Fatalf("Failed to set: %v", err)
}
})
}))
s.Wait(0)
suite.RunParallel(b, func(cb func(error)) error {
_, err := agent.Get(GetOptions{
Key: key,
}, func(result *GetResult, err error) {
cb(err)
})
return err
})
}
func BenchmarkSetGet(b *testing.B) {
b.ReportAllocs()
suite := GetBenchSuite()
agent := suite.GetAgent()
key := []byte(uuid.New().String())
// Generate 256 bytes of random data for the document
randomBytes := make([]byte, 256)
for i := 0; i < len(randomBytes); i++ {
randomBytes[i] = byte(i)
}
runGet := func(cb func(error)) {
_, err := agent.Get(GetOptions{
Key: key,
}, func(result *GetResult, err error) {
cb(err)
})
if err != nil {
cb(err)
}
}
suite.RunParallel(b, func(cb func(error)) error {
_, err := agent.Set(SetOptions{
Key: key,
Value: randomBytes,
}, func(result *StoreResult, err error) {
if err != nil {
cb(err)
return
}
runGet(cb)
})
return err
})
}