Skip to content

Commit

Permalink
fix: remove db after benchmark (#1)
Browse files Browse the repository at this point in the history
* fix: remove db after benchmark

Signed-off-by: rfyiamcool <[email protected]>
  • Loading branch information
rfyiamcool authored Aug 14, 2023
1 parent e5615c7 commit c58cbe0
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@ package benchmark

import (
"fmt"
"github.com/rosedblabs/diskhash"
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)

var t *diskhash.Table
"github.com/rosedblabs/diskhash"
"github.com/stretchr/testify/assert"
)

func init() {
func newDB() (*diskhash.Table, func()) {
options := diskhash.DefaultOptions
options.SlotValueLength = 16
options.DirPath = "/tmp/diskhash-bench"
var err error
t, err = diskhash.Open(options)
db, err := diskhash.Open(options)
if err != nil {
panic(err)
}

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

func BenchmarkPut(b *testing.B) {
db, closer := newDB()
defer closer()

b.ResetTimer()
b.ReportAllocs()

value := []byte(strings.Repeat("d", 16))
for i := 0; i < b.N; i++ {
err := t.Put(GetTestKey(i), []byte(strings.Repeat("d", 16)), func(slot diskhash.Slot) (bool, error) {
err := db.Put(GetTestKey(i), value, func(slot diskhash.Slot) (bool, error) {
return false, nil
})
assert.Nil(b, err)
Expand Down

0 comments on commit c58cbe0

Please sign in to comment.