Skip to content

Commit

Permalink
Only collect keys if using rnd read mode
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Baxter <[email protected]>
  • Loading branch information
ambaxter committed Apr 8, 2024
1 parent b451c9d commit 302a89f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cmd/bbolt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,20 +1107,29 @@ func (cmd *benchCommand) Run(args ...string) error {

// Write to the database.
var writeResults BenchResults
keys := make([]nestedKey, 0, options.Iterations)
var keys []nestedKey

if options.ReadMode == "rnd" {
keys = make([]nestedKey, 0, options.Iterations)
} else {
keys = nil
}

fmt.Fprintf(cmd.Stderr, "starting write benchmark.\n")
if err := cmd.runWrites(db, options, &writeResults, r, &keys); err != nil {
return fmt.Errorf("write: %v", err)
}

r.Shuffle(len(keys), func(i, j int) {
keys[i], keys[j] = keys[j], keys[i]
})
if keys != nil {
r.Shuffle(len(keys), func(i, j int) {
keys[i], keys[j] = keys[j], keys[i]
})
}

var readResults BenchResults
fmt.Fprintf(cmd.Stderr, "starting read benchmark.\n")
// Read from the database.
if err := cmd.runReads(db, options, &readResults, r, keys); err != nil {
if err := cmd.runReads(db, options, &readResults, keys); err != nil {
return fmt.Errorf("bench: read: %s", err)
}

Expand Down Expand Up @@ -1252,7 +1261,9 @@ func (cmd *benchCommand) runWritesWithSource(db *bolt.DB, options *BenchOptions,
if err := b.Put(key, value); err != nil {
return err
}
*keys = append(*keys, nestedKey{nil, key})
if *keys != nil {
*keys = append(*keys, nestedKey{nil, key})
}
results.AddCompletedOps(1)
}
fmt.Fprintf(cmd.Stderr, "Finished write iteration %d\n", i)
Expand Down Expand Up @@ -1297,7 +1308,9 @@ func (cmd *benchCommand) runWritesNestedWithSource(db *bolt.DB, options *BenchOp
if err := b.Put(key, value); err != nil {
return err
}
*keys = append(*keys, nestedKey{name, key})
if *keys != nil {
*keys = append(*keys, nestedKey{nil, key})
}
results.AddCompletedOps(1)
}
fmt.Fprintf(cmd.Stderr, "Finished write iteration %d\n", i)
Expand All @@ -1311,7 +1324,7 @@ func (cmd *benchCommand) runWritesNestedWithSource(db *bolt.DB, options *BenchOp
}

// Reads from the database.
func (cmd *benchCommand) runReads(db *bolt.DB, options *BenchOptions, results *BenchResults, r *rand.Rand, keys []nestedKey) error {
func (cmd *benchCommand) runReads(db *bolt.DB, options *BenchOptions, results *BenchResults, keys []nestedKey) error {
// Start profiling for reads.
if options.ProfileMode == "r" {
cmd.startProfiling(options)
Expand Down

0 comments on commit 302a89f

Please sign in to comment.