Skip to content

Commit

Permalink
Merge pull request #802 from tjungblu/nighty_bench_3.5
Browse files Browse the repository at this point in the history
[1.3] backport make build target and go bench output
  • Loading branch information
ahrtr authored Aug 1, 2024
2 parents 71159e3 + 138cbb3 commit 14c8aaf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
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

0 comments on commit 14c8aaf

Please sign in to comment.