Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove db after benchmark #1

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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