Commit 79fab70a authored by Marcel van Lohuizen's avatar Marcel van Lohuizen

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: 's avatarIan Lance Taylor <iant@golang.org>
parent d390283f
......@@ -657,9 +657,6 @@ func Benchmark(f func(b *B)) BenchmarkResult {
benchFunc: f,
benchTime: *benchTime,
}
if !b.run1() {
return BenchmarkResult{}
}
return b.run()
}
......
......@@ -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()))
}
}
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