-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbench_nutsdb_test.go
63 lines (55 loc) · 1.12 KB
/
bench_nutsdb_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
package contrast_benchmark
import (
"github.com/nutsdb/nutsdb"
"testing"
)
var nutsDB *nutsdb.DB
func init() {
opts := nutsdb.DefaultOptions
opts.Dir = "benchmark/nutsdb"
opts.SyncEnable = false
opts.EntryIdxMode = nutsdb.HintKeyAndRAMIdxMode
var err error
nutsDB, err = nutsdb.Open(opts)
if err != nil {
panic(err)
}
initNutsDBData()
}
func initNutsDBData() {
for i := 0; i < 500000; i++ {
nutsDB.Update(func(tx *nutsdb.Tx) error {
err := tx.Put("test-bucket", GetKey(i), GetValue(), 0)
if err != nil {
panic(err)
}
return nil
})
}
}
func Benchmark_PutValue_NutsDB(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
nutsDB.Update(func(tx *nutsdb.Tx) error {
err := tx.Put("test-bucket", GetKey(i), GetValue(), 0)
if err != nil {
panic(err)
}
return nil
})
}
}
func Benchmark_GetValue_NutsDB(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
nutsDB.View(func(tx *nutsdb.Tx) error {
_, err := tx.Get("test-bucket", GetKey(i))
if err != nil && err != nutsdb.ErrKeyNotFound {
panic(err)
}
return nil
})
}
}