Skip to content

Commit

Permalink
bbolt: Update benchmarks for gob
Browse files Browse the repository at this point in the history
Signed-off-by: Simarpreet Singh <simar@linux.com>
  • Loading branch information
simar7 committed Nov 21, 2019
1 parent 09b9892 commit 9849756
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
6 changes: 4 additions & 2 deletions bbolt/bbolt_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"sync"
"testing"

"github.com/simar7/gokv/encoding"

"github.com/simar7/gokv/types"

"github.com/stretchr/testify/assert"
Expand All @@ -14,7 +16,7 @@ import (
func benchmarkSet(j int, b *testing.B) {
b.ReportAllocs()

s, f, err := setupStore()
s, f, err := setupStoreWithCodec(encoding.JSON)
defer func() {
_ = f.Close()
_ = os.RemoveAll(f.Name())
Expand Down Expand Up @@ -46,7 +48,7 @@ func benchmarkSet(j int, b *testing.B) {
func benchmarkBatchSet(j int, b *testing.B) {
b.ReportAllocs()

s, f, err := setupStore()
s, f, err := setupStoreWithCodec(encoding.JSON)
defer func() {
_ = f.Close()
_ = os.RemoveAll(f.Name())
Expand Down
8 changes: 6 additions & 2 deletions bbolt/bbolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ import (
"github.com/stretchr/testify/assert"
)

func setupStore() (*Store, *os.File, error) {
func setupStoreWithCodec(codec encoding.Codec) (*Store, *os.File, error) {
f, err := ioutil.TempFile(".", "Bolt_TestStore_Get-*")
if err != nil {
return nil, nil, err
}

s, err := NewStore(Options{Path: f.Name()})
s, err := NewStore(Options{Path: f.Name(), Codec: codec})
return s, f, err
}

func setupStore() (*Store, *os.File, error) {
return setupStoreWithCodec(encoding.JSON)
}

func TestNewStore(t *testing.T) {
testCases := []struct {
name string
Expand Down
26 changes: 18 additions & 8 deletions bbolt/bench.results
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
Format: Benchmark{Function_Name}_{Goroutine_Count}

BenchmarkStore_Set_10-8 7 148262680 ns/op 90536 B/op 561 allocs/op
BenchmarkStore_BatchSet_10-8 43 25739238 ns/op 14903 B/op 174 allocs/op
Codec: JSON
-----------
BenchmarkStore_Set_10-8 4 287203197 ns/op 166494 B/op 1218 allocs/op
BenchmarkStore_BatchSet_10-8 48 24649885 ns/op 17382 B/op 236 allocs/op

BenchmarkStore_Set_100-8 1 1389692456 ns/op 1800696 B/op 5729 allocs/op
BenchmarkStore_BatchSet_100-8 43 26573247 ns/op 69442 B/op 1182 allocs/op
BenchmarkStore_Set_100-8 1 2686920561 ns/op 2456736 B/op 11318 allocs/op
BenchmarkStore_BatchSet_100-8 48 24819310 ns/op 84989 B/op 1597 allocs/op

BenchmarkStore_Set_1000-8 1 14204090885 ns/op 29077600 B/op 61877 allocs/op
BenchmarkStore_BatchSet_1000-8 39 27656939 ns/op 685556 B/op 12515 allocs/op
BenchmarkStore_Set_1000-8 1 26768086250 ns/op 36138808 B/op 120545 allocs/op
BenchmarkStore_BatchSet_1000-8 42 28252055 ns/op 841488 B/op 16593 allocs/op

BenchmarkStore_Set_10000-8 1 135506772987 ns/op 336269280 B/op 629670 allocs/op
BenchmarkStore_BatchSet_10000-8 6 168122801 ns/op 8537401 B/op 136949 allocs/op
Codec: Gob
----------
BenchmarkStore_Set_10-8 4 285566068 ns/op 173706 B/op 1323 allocs/op
BenchmarkStore_BatchSet_10-8 46 24549045 ns/op 26445 B/op 345 allocs/op

BenchmarkStore_Set_100-8 1 2639456621 ns/op 2545608 B/op 12341 allocs/op
BenchmarkStore_BatchSet_100-8 46 25044494 ns/op 166920 B/op 2609 allocs/op

BenchmarkStore_Set_1000-8 1 26472035638 ns/op 35322664 B/op 130541 allocs/op
BenchmarkStore_BatchSet_1000-8 39 28649827 ns/op 1664744 B/op 26710 allocs/op

0 comments on commit 9849756

Please sign in to comment.