-
Notifications
You must be signed in to change notification settings - Fork 2
/
bench_flydb_test.go
52 lines (42 loc) · 965 Bytes
/
bench_flydb_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
package contrast_benchmark
import (
"github.com/ByteStorage/FlyDB/config"
"github.com/ByteStorage/FlyDB/engine"
"github.com/ByteStorage/FlyDB/flydb"
_const "github.com/ByteStorage/FlyDB/lib/const"
"github.com/stretchr/testify/assert"
"path/filepath"
"testing"
)
var FlyDB *engine.DB
var err error
func init() {
opts := config.DefaultOptions
opts.DirPath = filepath.Join("benchmark", "flydb")
FlyDB, err = flydb.NewFlyDB(opts)
if err != nil {
panic(err)
}
}
func Benchmark_PutValue_FlyDB(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
err = FlyDB.Put(GetKey(n), GetValue())
assert.Nil(b, err)
}
}
func Benchmark_GetValue_FlyDB(b *testing.B) {
for i := 0; i < 500000; i++ {
err = FlyDB.Put(GetKey(i), GetValue())
assert.Nil(b, err)
}
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_, err = FlyDB.Get(GetKey(n))
if err != nil && err != _const.ErrKeyNotFound {
panic(err)
}
}
}