mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
d390283ff4
commit
79fab70a63
2 changed files with 20 additions and 3 deletions
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue