diff options
| author | Russ Cox <rsc@golang.org> | 2017-06-16 14:46:24 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2017-06-20 14:19:05 +0000 |
| commit | a2a3ace51aa0600765d44a71f47fd830fa6217c5 (patch) | |
| tree | a26628d8938b71fcd9132f9f10a6c6d7931059d6 /src/testing/benchmark.go | |
| parent | be855e3f28507dd3e34eb4699c84493eeaae68db (diff) | |
| download | go-a2a3ace51aa0600765d44a71f47fd830fa6217c5.tar.xz | |
testing: harmonize handling of prefix-matched benchmarks
If you have BenchmarkX1 with sub-benchmark Y
and you have BenchmarkX2 with no sub-benchmarks,
then
go test -bench=X/Y
runs BenchmarkX1 once with b.N=1 (to find out about Y)
and then not again, because it has sub-benchmarks,
but arguably also because we're interested in Y.
In contrast, it runs BenchmarkX2 in full, even though clearly
that is not relevant to the match X/Y. We do have to run X2
once with b.N=1 to probe for having X2/Y, but we should not
run it with larger b.N.
Fixes #20589.
Change-Id: Ib86907e844f34dcaac6cd05757f57db1019201d0
Reviewed-on: https://go-review.googlesource.com/46031
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Diffstat (limited to 'src/testing/benchmark.go')
| -rw-r--r-- | src/testing/benchmark.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go index 18a46d93bf..8b7f5cebaf 100644 --- a/src/testing/benchmark.go +++ b/src/testing/benchmark.go @@ -405,7 +405,7 @@ func runBenchmarks(importPath string, matchString func(pat, str string) (bool, e } var bs []InternalBenchmark for _, Benchmark := range benchmarks { - if _, matched := ctx.match.fullName(nil, Benchmark.Name); matched { + if _, matched, _ := ctx.match.fullName(nil, Benchmark.Name); matched { bs = append(bs, Benchmark) benchName := benchmarkName(Benchmark.Name, maxprocs) if l := len(benchName) + ctx.extLen + 1; l > ctx.maxLen { @@ -492,9 +492,9 @@ func (b *B) Run(name string, f func(b *B)) bool { benchmarkLock.Unlock() defer benchmarkLock.Lock() - benchName, ok := b.name, true + benchName, ok, partial := b.name, true, false if b.context != nil { - benchName, ok = b.context.match.fullName(&b.common, name) + benchName, ok, partial = b.context.match.fullName(&b.common, name) } if !ok { return true @@ -513,6 +513,11 @@ func (b *B) Run(name string, f func(b *B)) bool { benchTime: b.benchTime, context: b.context, } + if partial { + // Partial name match, like -bench=X/Y matching BenchmarkX. + // Only process sub-benchmarks, if any. + atomic.StoreInt32(&sub.hasSub, 1) + } if sub.run1() { sub.run() } |
