Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.3] backport make build target and go bench output #802

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ coverage:
TEST_FREELIST_TYPE=array go test -v -timeout 30m \
-coverprofile cover-freelist-array.out -covermode atomic

BOLT_CMD=bbolt

build:
go build -o bin/${BOLT_CMD} ./cmd/${BOLT_CMD}

.PHONY: clean
clean: # Clean binaries
rm -f ./bin/${BOLT_CMD}

.PHONY: gofail-enable
gofail-enable: install-gofail
gofail enable .
Expand Down
26 changes: 23 additions & 3 deletions cmd/bbolt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"runtime/pprof"
"strconv"
"strings"
"testing"
"time"
"unicode"
"unicode/utf8"
Expand Down Expand Up @@ -1114,9 +1115,26 @@ func (cmd *benchCommand) Run(args ...string) error {
}

// Print results.
fmt.Fprintf(os.Stderr, "# Write\t%v\t(%v/op)\t(%v op/sec)\n", results.WriteDuration, results.WriteOpDuration(), results.WriteOpsPerSecond())
fmt.Fprintf(os.Stderr, "# Read\t%v\t(%v/op)\t(%v op/sec)\n", results.ReadDuration, results.ReadOpDuration(), results.ReadOpsPerSecond())
fmt.Fprintln(os.Stderr, "")
if options.GoBenchOutput {
// below replicates the output of testing.B benchmarks, e.g. for external tooling
benchWriteName := "BenchmarkWrite"
benchReadName := "BenchmarkRead"
maxLen := max(len(benchReadName), len(benchWriteName))
gobenchResult := testing.BenchmarkResult{}
gobenchResult.T = results.WriteDuration
gobenchResult.N = results.WriteOps
fmt.Fprintf(os.Stderr, "%-*s\t%s\n", maxLen, benchWriteName, gobenchResult.String())

gobenchResult = testing.BenchmarkResult{}
gobenchResult.T = results.ReadDuration
gobenchResult.N = results.ReadOps
fmt.Fprintf(os.Stderr, "%-*s\t%s\n", maxLen, benchReadName, gobenchResult.String())
} else {
fmt.Fprintf(os.Stderr, "# Write\t%v\t(%v/op)\t(%v op/sec)\n", results.WriteDuration, results.WriteOpDuration(), results.WriteOpsPerSecond())
fmt.Fprintf(os.Stderr, "# Read\t%v\t(%v/op)\t(%v op/sec)\n", results.ReadDuration, results.ReadOpDuration(), results.ReadOpsPerSecond())
}
fmt.Fprintln(cmd.Stderr, "")

return nil
}

Expand All @@ -1140,6 +1158,7 @@ func (cmd *benchCommand) ParseFlags(args []string) (*BenchOptions, error) {
fs.BoolVar(&options.NoSync, "no-sync", false, "")
fs.BoolVar(&options.Work, "work", false, "")
fs.StringVar(&options.Path, "path", "", "")
fs.BoolVar(&options.GoBenchOutput, "gobench-output", false, "")
fs.SetOutput(cmd.Stderr)
if err := fs.Parse(args); err != nil {
return nil, err
Expand Down Expand Up @@ -1482,6 +1501,7 @@ type BenchOptions struct {
NoSync bool
Work bool
Path string
GoBenchOutput bool
}

// BenchResults represents the performance results of the benchmark.
Expand Down
Loading