Skip to content

Commit

Permalink
fix: clear db after benchmark (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfyiamcool authored Jul 2, 2023
1 parent af16e97 commit 8a7240b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package benchmark

import (
"math/rand"
"os"
"testing"

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

var db *rosedb.DB

func init() {
func openDB() func() {
options := rosedb.DefaultOptions
options.DirPath = "/tmp/rosedbv2"

Expand All @@ -20,9 +21,22 @@ func init() {
if err != nil {
panic(err)
}

return func() {
_ = db.Close()
_ = os.RemoveAll(options.DirPath)
}
}

func BenchmarkPutGet(b *testing.B) {
closer := openDB()
defer closer()

b.Run("put", benchmarkPut)
b.Run("get", bencharkGet)
}

func Benchmark_Put(b *testing.B) {
func benchmarkPut(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

Expand All @@ -32,7 +46,7 @@ func Benchmark_Put(b *testing.B) {
}
}

func Benchmark_Get(b *testing.B) {
func bencharkGet(b *testing.B) {
for i := 0; i < 10000; i++ {
err := db.Put(utils.GetTestKey(i), utils.RandomValue(1024))
assert.Nil(b, err)
Expand Down

0 comments on commit 8a7240b

Please sign in to comment.