]> Cypherpunks.ru repositories - gostls13.git/commitdiff
testing: fix stats bug for sub benchmarks
authorMarcel van Lohuizen <mpvl@golang.org>
Tue, 14 Feb 2017 12:01:18 +0000 (13:01 +0100)
committerMarcel van Lohuizen <mpvl@golang.org>
Wed, 15 Feb 2017 09:26:33 +0000 (09:26 +0000)
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>
src/testing/benchmark.go
src/testing/sub_test.go

index 3233347dcbd88236bd236573379969e2d18b7ed9..86c0f10ecdc1d960cc69d9bd1a78606a59fe59cc 100644 (file)
@@ -657,9 +657,6 @@ func Benchmark(f func(b *B)) BenchmarkResult {
                benchFunc: f,
                benchTime: *benchTime,
        }
-       if !b.run1() {
-               return BenchmarkResult{}
-       }
        return b.run()
 }
 
index c12a2c807ab95a1faba8509b59b556da3a1636d3..fe3e8ff8581ea024261204ad3454e972623ee6e0 100644 (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()))
+       }
+}