File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package benchmark
22
33import (
44 "math/rand"
5+ "os"
56 "testing"
67
78 "github.com/rosedblabs/rosedb/v2"
@@ -11,7 +12,7 @@ import (
1112
1213var db * rosedb.DB
1314
14- func init () {
15+ func openDB () func () {
1516 options := rosedb .DefaultOptions
1617 options .DirPath = "/tmp/rosedbv2"
1718
@@ -20,9 +21,22 @@ func init() {
2021 if err != nil {
2122 panic (err )
2223 }
24+
25+ return func () {
26+ _ = db .Close ()
27+ _ = os .RemoveAll (options .DirPath )
28+ }
29+ }
30+
31+ func BenchmarkPutGet (b * testing.B ) {
32+ closer := openDB ()
33+ defer closer ()
34+
35+ b .Run ("put" , benchmarkPut )
36+ b .Run ("get" , bencharkGet )
2337}
2438
25- func Benchmark_Put (b * testing.B ) {
39+ func benchmarkPut (b * testing.B ) {
2640 b .ResetTimer ()
2741 b .ReportAllocs ()
2842
@@ -32,7 +46,7 @@ func Benchmark_Put(b *testing.B) {
3246 }
3347}
3448
35- func Benchmark_Get (b * testing.B ) {
49+ func bencharkGet (b * testing.B ) {
3650 for i := 0 ; i < 10000 ; i ++ {
3751 err := db .Put (utils .GetTestKey (i ), utils .RandomValue (1024 ))
3852 assert .Nil (b , err )
You can’t perform that action at this time.
0 commit comments