1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:44:42 -07:00

testing: fix stats bug for sub benchmarks

Fixes golang/go#18815.

Change-Id: Ic9d5cb640a555c58baedd597ed4ca5dd9f275c97
Reviewed-on: https://go-review.googlesource.com/36990
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Marcel van Lohuizen 2017-02-14 13:01:18 +01:00
parent d390283ff4
commit 79fab70a63
2 changed files with 20 additions and 3 deletions

View File

@ -657,9 +657,6 @@ func Benchmark(f func(b *B)) BenchmarkResult {
benchFunc: f,
benchTime: *benchTime,
}
if !b.run1() {
return BenchmarkResult{}
}
return b.run()
}

View File

@ -15,6 +15,11 @@ import (
"time"
)
func init() {
// Make benchmark tests run 10* faster.
*benchTime = 100 * time.Millisecond
}
func TestTestContext(t *T) {
const (
add1 = 0
@ -581,3 +586,18 @@ func TestRacyOutput(t *T) {
t.Errorf("detected %d racy Writes", races)
}
}
func TestBenchmark(t *T) {
res := Benchmark(func(b *B) {
for i := 0; i < 5; i++ {
b.Run("", func(b *B) {
for i := 0; i < b.N; i++ {
time.Sleep(time.Millisecond)
}
})
}
})
if res.NsPerOp() < 4000000 {
t.Errorf("want >5ms; got %v", time.Duration(res.NsPerOp()))
}
}