-
Notifications
You must be signed in to change notification settings - Fork 151
/
benchmark_io.go
48 lines (39 loc) · 1.19 KB
/
benchmark_io.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
package toolset
import (
"fmt"
"sync"
"github.com/iotaledger/hive.go/kvstore"
)
type benchmarkObject struct {
store kvstore.KVStore
writeDoneWaitGroup *sync.WaitGroup
key []byte
value []byte
}
func newBenchmarkObject(store kvstore.KVStore, writeDoneWaitGroup *sync.WaitGroup, key []byte, value []byte) *benchmarkObject {
return &benchmarkObject{
store: store,
writeDoneWaitGroup: writeDoneWaitGroup,
key: key,
value: value,
}
}
func (bo *benchmarkObject) BatchWrite(batchedMuts kvstore.BatchedMutations) {
if err := batchedMuts.Set(bo.key, bo.value); err != nil {
panic(fmt.Errorf("write operation failed: %v", err))
}
}
func (bo *benchmarkObject) BatchWriteDone() {
// do a read operation after the batchwrite is done,
// so the write and read operations are equally distributed over the whole benchmark run.
if _, err := bo.store.Has(randBytes(32)); err != nil {
panic(fmt.Errorf("read operation failed: %v", err))
}
bo.writeDoneWaitGroup.Done()
}
func (bo *benchmarkObject) BatchWriteScheduled() bool {
return false
}
func (bo *benchmarkObject) ResetBatchWriteScheduled() {
// do nothing
}