Skip to content

Commit 31526df

Browse files
committed
add bench command
also adds a dedicated simulation test Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
1 parent 37a8e0e commit 31526df

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

cmd/bbolt/command/command_bench.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type benchOptions struct {
4141
pageSize int
4242
initialMmapSize int
4343
deleteFraction float64 // Fraction of keys of last tx to delete during writes. works only with "seq-del" write mode.
44+
compression bool
4445
}
4546

4647
func (o *benchOptions) AddFlags(fs *pflag.FlagSet) {
@@ -61,6 +62,7 @@ func (o *benchOptions) AddFlags(fs *pflag.FlagSet) {
6162
fs.BoolVar(&o.goBenchOutput, "gobench-output", false, "")
6263
fs.IntVar(&o.pageSize, "page-size", common.DefaultPageSize, "Set page size in bytes.")
6364
fs.IntVar(&o.initialMmapSize, "initial-mmap-size", 0, "Set initial mmap size in bytes for database file.")
65+
fs.BoolVar(&o.compression, "compression", false, "Enables compression.")
6466
}
6567

6668
// Returns an error if `bench` options are not valid.
@@ -145,6 +147,7 @@ func benchFunc(cmd *cobra.Command, options *benchOptions) error {
145147
dbOptions := *bolt.DefaultOptions
146148
dbOptions.PageSize = options.pageSize
147149
dbOptions.InitialMmapSize = options.initialMmapSize
150+
dbOptions.Compression = options.compression
148151
db, err := bolt.Open(options.path, 0600, &dbOptions)
149152
if err != nil {
150153
return err

cmd/bbolt/command/command_bench_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ func TestBenchCommand_Run(t *testing.T) {
3838
tests := map[string]struct {
3939
args []string
4040
}{
41-
"no-args": {},
42-
"100k count": {[]string{"--count", "100000"}},
41+
"no-args": {},
42+
"100k count": {[]string{"--count", "100000"}},
43+
"compression": {[]string{"--compression"}},
4344
}
4445

4546
for name, test := range tests {

simulation_compression_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package bbolt_test
2+
3+
import (
4+
"testing"
5+
6+
bolt "go.etcd.io/bbolt"
7+
)
8+
9+
func TestSimulateCompression_1op_1p(t *testing.T) {
10+
testSimulate(t, &bolt.Options{Compression: true}, 8, 1, 1)
11+
}
12+
func TestSimulateCompression_10op_1p(t *testing.T) {
13+
testSimulate(t, &bolt.Options{Compression: true}, 8, 10, 1)
14+
}
15+
func TestSimulateCompression_100op_1p(t *testing.T) {
16+
testSimulate(t, &bolt.Options{Compression: true}, 8, 100, 1)
17+
}
18+
func TestSimulateCompression_1000op_1p(t *testing.T) {
19+
testSimulate(t, &bolt.Options{Compression: true}, 8, 1000, 1)
20+
}
21+
func TestSimulateCompression_10000op_1p(t *testing.T) {
22+
testSimulate(t, &bolt.Options{Compression: true}, 8, 10000, 1)
23+
}
24+
func TestSimulateCompression_10op_10p(t *testing.T) {
25+
testSimulate(t, &bolt.Options{Compression: true}, 8, 10, 10)
26+
}
27+
func TestSimulateCompression_100op_10p(t *testing.T) {
28+
testSimulate(t, &bolt.Options{Compression: true}, 8, 100, 10)
29+
}
30+
func TestSimulateCompression_1000op_10p(t *testing.T) {
31+
testSimulate(t, &bolt.Options{Compression: true}, 8, 1000, 10)
32+
}
33+
func TestSimulateCompression_10000op_10p(t *testing.T) {
34+
testSimulate(t, &bolt.Options{Compression: true}, 8, 10000, 10)
35+
}
36+
func TestSimulateCompression_100op_100p(t *testing.T) {
37+
testSimulate(t, &bolt.Options{Compression: true}, 8, 100, 100)
38+
}
39+
func TestSimulateCompression_1000op_100p(t *testing.T) {
40+
testSimulate(t, &bolt.Options{Compression: true}, 8, 1000, 100)
41+
}
42+
func TestSimulateCompression_10000op_100p(t *testing.T) {
43+
testSimulate(t, &bolt.Options{Compression: true}, 8, 10000, 100)
44+
}
45+
func TestSimulateCompression_10000op_1000p(t *testing.T) {
46+
testSimulate(t, &bolt.Options{Compression: true}, 8, 10000, 1000)
47+
}

0 commit comments

Comments
 (0)