Skip to content

Commit

Permalink
fix benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
roseduan committed Jan 12, 2025
1 parent 5ac7f6c commit ffdcf94
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"math/rand"
"os"
"runtime"
"testing"

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

func openDB() func() {
options := rosedb.DefaultOptions
options.DirPath = "/tmp/rosedbv2"
sysType := runtime.GOOS
if sysType == "windows" {
options.DirPath = "C:\\rosedb_bench_test"
} else {
options.DirPath = "/tmp/rosedb_bench_test"
}

var err error
db, err = rosedb.Open(options)
Expand Down Expand Up @@ -60,7 +66,9 @@ func benchmarkBatchPut(b *testing.B) {
b.ReportAllocs()

batch := db.NewBatch(rosedb.DefaultBatchOptions)
defer batch.Commit()
defer func() {
_ = batch.Commit()
}()
for i := 0; i < b.N; i++ {
err := batch.Put(utils.GetTestKey(i), utils.RandomValue(1024))
assert.Nil(b, err)
Expand All @@ -76,7 +84,9 @@ func benchmarkBatchGet(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
batch := db.NewBatch(rosedb.DefaultBatchOptions)
defer batch.Commit()
defer func() {
_ = batch.Commit()
}()
for i := 0; i < b.N; i++ {
_, err := batch.Get(utils.GetTestKey(rand.Int()))
if err != nil && !errors.Is(err, rosedb.ErrKeyNotFound) {
Expand Down

0 comments on commit ffdcf94

Please sign in to comment.