Skip to content

Commit

Permalink
cmd/bbolt: write bench results to stdout
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Valdes <[email protected]>
  • Loading branch information
ivanvc committed Jun 11, 2024
1 parent 29ffc08 commit 8704e5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cmd/bbolt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,11 +1056,11 @@ func (cmd *benchCommand) Run(args ...string) error {
benchWriteName := "BenchmarkWrite"
benchReadName := "BenchmarkRead"
maxLen := max(len(benchReadName), len(benchWriteName))
printGoBenchResult(cmd.Stderr, writeResults, maxLen, benchWriteName)
printGoBenchResult(cmd.Stderr, readResults, maxLen, benchReadName)
printGoBenchResult(cmd.Stdout, writeResults, maxLen, benchWriteName)
printGoBenchResult(cmd.Stdout, readResults, maxLen, benchReadName)
} else {
fmt.Fprintf(cmd.Stderr, "# Write\t%v(ops)\t%v\t(%v/op)\t(%v op/sec)\n", writeResults.CompletedOps(), writeResults.Duration(), writeResults.OpDuration(), writeResults.OpsPerSecond())
fmt.Fprintf(cmd.Stderr, "# Read\t%v(ops)\t%v\t(%v/op)\t(%v op/sec)\n", readResults.CompletedOps(), readResults.Duration(), readResults.OpDuration(), readResults.OpsPerSecond())
fmt.Fprintf(cmd.Stdout, "# Write\t%v(ops)\t%v\t(%v/op)\t(%v op/sec)\n", writeResults.CompletedOps(), writeResults.Duration(), writeResults.OpDuration(), writeResults.OpsPerSecond())
fmt.Fprintf(cmd.Stdout, "# Read\t%v(ops)\t%v\t(%v/op)\t(%v op/sec)\n", readResults.CompletedOps(), readResults.Duration(), readResults.OpDuration(), readResults.OpsPerSecond())
}
fmt.Fprintln(cmd.Stderr, "")

Expand Down
5 changes: 3 additions & 2 deletions cmd/bbolt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ func TestBenchCommand_Run(t *testing.T) {
}

stderr := m.Stderr.String()
stdout := m.Stdout.String()
if !strings.Contains(stderr, "starting write benchmark.") || !strings.Contains(stderr, "starting read benchmark.") {
t.Fatal(fmt.Errorf("benchmark result does not contain read/write start output:\n%s", stderr))
}
Expand All @@ -492,8 +493,8 @@ func TestBenchCommand_Run(t *testing.T) {
t.Fatal(fmt.Errorf("found iter mismatch in stdout:\n%s", stderr))
}

if !strings.Contains(stderr, "# Write") || !strings.Contains(stderr, "# Read") {
t.Fatal(fmt.Errorf("benchmark result does not contain read/write output:\n%s", stderr))
if !strings.Contains(stdout, "# Write") || !strings.Contains(stdout, "# Read") {
t.Fatal(fmt.Errorf("benchmark result does not contain read/write output:\n%s", stdout))
}
})
}
Expand Down

0 comments on commit 8704e5e

Please sign in to comment.