Skip to content

Commit 8a7240b

Browse files
authored
fix: clear db after benchmark (#224)
1 parent af16e97 commit 8a7240b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

benchmark/bench_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package benchmark
22

33
import (
44
"math/rand"
5+
"os"
56
"testing"
67

78
"github.com/rosedblabs/rosedb/v2"
@@ -11,7 +12,7 @@ import (
1112

1213
var db *rosedb.DB
1314

14-
func init() {
15+
func openDB() func() {
1516
options := rosedb.DefaultOptions
1617
options.DirPath = "/tmp/rosedbv2"
1718

@@ -20,9 +21,22 @@ func init() {
2021
if err != nil {
2122
panic(err)
2223
}
24+
25+
return func() {
26+
_ = db.Close()
27+
_ = os.RemoveAll(options.DirPath)
28+
}
29+
}
30+
31+
func BenchmarkPutGet(b *testing.B) {
32+
closer := openDB()
33+
defer closer()
34+
35+
b.Run("put", benchmarkPut)
36+
b.Run("get", bencharkGet)
2337
}
2438

25-
func Benchmark_Put(b *testing.B) {
39+
func benchmarkPut(b *testing.B) {
2640
b.ResetTimer()
2741
b.ReportAllocs()
2842

@@ -32,7 +46,7 @@ func Benchmark_Put(b *testing.B) {
3246
}
3347
}
3448

35-
func Benchmark_Get(b *testing.B) {
49+
func bencharkGet(b *testing.B) {
3650
for i := 0; i < 10000; i++ {
3751
err := db.Put(utils.GetTestKey(i), utils.RandomValue(1024))
3852
assert.Nil(b, err)

0 commit comments

Comments
 (0)