Skip to content

Commit ffdcf94

Browse files
committed
fix benchmark
1 parent 5ac7f6c commit ffdcf94

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

benchmark/bench_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"math/rand"
66
"os"
7+
"runtime"
78
"testing"
89

910
"github.com/rosedblabs/rosedb/v2"
@@ -15,7 +16,12 @@ var db *rosedb.DB
1516

1617
func openDB() func() {
1718
options := rosedb.DefaultOptions
18-
options.DirPath = "/tmp/rosedbv2"
19+
sysType := runtime.GOOS
20+
if sysType == "windows" {
21+
options.DirPath = "C:\\rosedb_bench_test"
22+
} else {
23+
options.DirPath = "/tmp/rosedb_bench_test"
24+
}
1925

2026
var err error
2127
db, err = rosedb.Open(options)
@@ -60,7 +66,9 @@ func benchmarkBatchPut(b *testing.B) {
6066
b.ReportAllocs()
6167

6268
batch := db.NewBatch(rosedb.DefaultBatchOptions)
63-
defer batch.Commit()
69+
defer func() {
70+
_ = batch.Commit()
71+
}()
6472
for i := 0; i < b.N; i++ {
6573
err := batch.Put(utils.GetTestKey(i), utils.RandomValue(1024))
6674
assert.Nil(b, err)
@@ -76,7 +84,9 @@ func benchmarkBatchGet(b *testing.B) {
7684
b.ResetTimer()
7785
b.ReportAllocs()
7886
batch := db.NewBatch(rosedb.DefaultBatchOptions)
79-
defer batch.Commit()
87+
defer func() {
88+
_ = batch.Commit()
89+
}()
8090
for i := 0; i < b.N; i++ {
8191
_, err := batch.Get(utils.GetTestKey(rand.Int()))
8292
if err != nil && !errors.Is(err, rosedb.ErrKeyNotFound) {

0 commit comments

Comments
 (0)