aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorMarcel van Lohuizen <mpvl@golang.org>2017-02-14 13:01:18 +0100
committerMarcel van Lohuizen <mpvl@golang.org>2017-02-15 09:26:33 +0000
commit79fab70a63e03897db384fbf1b5fdeeb6f9f4b92 (patch)
treeccc545dbf945b5f42b18284d7aa471895bda2874 /src/testing
parentd390283ff42c44230ac25800efca231b952fd3ed (diff)
downloadgo-79fab70a63e03897db384fbf1b5fdeeb6f9f4b92.tar.xz
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>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/benchmark.go3
-rw-r--r--src/testing/sub_test.go20
2 files changed, 20 insertions, 3 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go
index 3233347dcb..86c0f10ecd 100644
--- a/src/testing/benchmark.go
+++ b/src/testing/benchmark.go
@@ -657,9 +657,6 @@ func Benchmark(f func(b *B)) BenchmarkResult {
benchFunc: f,
benchTime: *benchTime,
}
- if !b.run1() {
- return BenchmarkResult{}
- }
return b.run()
}
diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go
index c12a2c807a..fe3e8ff858 100644
--- a/src/testing/sub_test.go
+++ b/src/testing/sub_test.go
@@ -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()))
+ }
+}