Commit 3d56fe6d authored by Håvard Haugen's avatar Håvard Haugen Committed by Andrew Gerrand

testing: pad benchmark names to align results

Fixes #8780

Change-Id: I09cf01ff9722eed49086992a12774f2de81d16f2
Reviewed-on: https://go-review.googlesource.com/2840Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 6f999f23
...@@ -280,6 +280,14 @@ func (r BenchmarkResult) MemString() string { ...@@ -280,6 +280,14 @@ func (r BenchmarkResult) MemString() string {
r.AllocedBytesPerOp(), r.AllocsPerOp()) r.AllocedBytesPerOp(), r.AllocsPerOp())
} }
// benchmarkName returns full name of benchmark including procs suffix.
func benchmarkName(name string, n int) string {
if n != 1 {
return fmt.Sprintf("%s-%d", name, n)
}
return name
}
// An internal function but exported because it is cross-package; part of the implementation // An internal function but exported because it is cross-package; part of the implementation
// of the "go test" command. // of the "go test" command.
func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) { func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) {
...@@ -287,15 +295,30 @@ func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [ ...@@ -287,15 +295,30 @@ func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [
if len(*matchBenchmarks) == 0 { if len(*matchBenchmarks) == 0 {
return return
} }
// Collect matching benchmarks and determine longest name.
maxprocs := 1
for _, procs := range cpuList {
if procs > maxprocs {
maxprocs = procs
}
}
maxlen := 0
var bs []InternalBenchmark
for _, Benchmark := range benchmarks { for _, Benchmark := range benchmarks {
matched, err := matchString(*matchBenchmarks, Benchmark.Name) matched, err := matchString(*matchBenchmarks, Benchmark.Name)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.bench: %s\n", err) fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.bench: %s\n", err)
os.Exit(1) os.Exit(1)
} }
if !matched { if matched {
continue bs = append(bs, Benchmark)
benchName := benchmarkName(Benchmark.Name, maxprocs)
if l := len(benchName); l > maxlen {
maxlen = l
}
} }
}
for _, Benchmark := range bs {
for _, procs := range cpuList { for _, procs := range cpuList {
runtime.GOMAXPROCS(procs) runtime.GOMAXPROCS(procs)
b := &B{ b := &B{
...@@ -304,11 +327,8 @@ func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [ ...@@ -304,11 +327,8 @@ func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [
}, },
benchmark: Benchmark, benchmark: Benchmark,
} }
benchName := Benchmark.Name benchName := benchmarkName(Benchmark.Name, procs)
if procs != 1 { fmt.Printf("%-*s\t", maxlen, benchName)
benchName = fmt.Sprintf("%s-%d", Benchmark.Name, procs)
}
fmt.Printf("%s\t", benchName)
r := b.run() r := b.run()
if b.failed { if b.failed {
// The output could be very long here, but probably isn't. // The output could be very long here, but probably isn't.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment