]> Cypherpunks.ru repositories - gostls13.git/commitdiff
Revert "testing: only compute b.N once when passed -count > 1"
authorAlberto Donizetti <alb.donizetti@gmail.com>
Thu, 31 May 2018 12:04:07 +0000 (12:04 +0000)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Thu, 31 May 2018 14:22:44 +0000 (14:22 +0000)
This reverts golang.org/cl/110775

Reason for revert: this is causing huge slow-dows on every run after
the 1st, on various benchmarks, on multiple architectures (see Issue
25622 for details). It's just a nice-to-have little optimization, and
we're near the 1st go1.11 beta release, so I'm reverting it.

Fixes #25622

Change-Id: I758ade4af4abf764abd8336d404396992d11a0c6
Reviewed-on: https://go-review.googlesource.com/115535
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/go/go_test.go
src/testing/benchmark.go

index c32be94823086077d35628fbf27536c584bed227..0f86834079d152e671b8a0c1f9581602915e77f7 100644 (file)
@@ -4911,6 +4911,10 @@ func TestTestRegexps(t *testing.T) {
     x_test.go:15: LOG: Y running N=2000000000
 --- BENCH: BenchmarkX/Y
     x_test.go:15: LOG: Y running N=1
+    x_test.go:15: LOG: Y running N=100
+    x_test.go:15: LOG: Y running N=10000
+    x_test.go:15: LOG: Y running N=1000000
+    x_test.go:15: LOG: Y running N=100000000
     x_test.go:15: LOG: Y running N=2000000000
 --- BENCH: BenchmarkX
     x_test.go:13: LOG: X running N=1
index bef1492cd6976e5a94afbbb397098ab964a2f77a..9c7b1be79e74389f2edefaf5ac8bda5a0f1a194a 100644 (file)
@@ -251,20 +251,27 @@ func (b *B) run() {
                b.context.processBench(b) // Must call doBench.
        } else {
                // Running func Benchmark.
-               b.doBench(0)
+               b.doBench()
        }
 }
 
-func (b *B) doBench(hint int) BenchmarkResult {
-       go b.launch(hint)
+func (b *B) doBench() BenchmarkResult {
+       go b.launch()
        <-b.signal
        return b.result
 }
 
-// autodetectN runs the benchmark function, gradually increasing the
-// number of iterations until the benchmark runs for the requested
-// benchtime.
-func (b *B) autodetectN() {
+// launch launches the benchmark function. It gradually increases the number
+// of benchmark iterations until the benchmark runs for the requested benchtime.
+// launch is run by the doBench function as a separate goroutine.
+// run1 must have been called on b.
+func (b *B) launch() {
+       // Signal that we're done whether we return normally
+       // or by FailNow's runtime.Goexit.
+       defer func() {
+               b.signal <- true
+       }()
+
        // Run the benchmark for at least the specified amount of time.
        d := b.benchTime
        for n := 1; !b.failed && b.duration < d && n < 1e9; {
@@ -282,26 +289,6 @@ func (b *B) autodetectN() {
                n = roundUp(n)
                b.runN(n)
        }
-}
-
-// launch launches the benchmark function for hintN iterations. If
-// hintN == 0, it autodetects the number of benchmark iterations based
-// on the requested benchtime.
-// launch is run by the doBench function as a separate goroutine.
-// run1 must have been called on b.
-func (b *B) launch(hintN int) {
-       // Signal that we're done whether we return normally
-       // or by FailNow's runtime.Goexit.
-       defer func() {
-               b.signal <- true
-       }()
-
-       if hintN == 0 {
-               b.autodetectN()
-       } else {
-               b.runN(hintN)
-       }
-
        b.result = BenchmarkResult{b.N, b.duration, b.bytes, b.netAllocs, b.netBytes}
 }
 
@@ -439,7 +426,6 @@ func runBenchmarks(importPath string, matchString func(pat, str string) (bool, e
 // processBench runs bench b for the configured CPU counts and prints the results.
 func (ctx *benchContext) processBench(b *B) {
        for i, procs := range cpuList {
-               var nHint int
                for j := uint(0); j < *count; j++ {
                        runtime.GOMAXPROCS(procs)
                        benchName := benchmarkName(b.name, procs)
@@ -458,10 +444,7 @@ func (ctx *benchContext) processBench(b *B) {
                                }
                                b.run1()
                        }
-                       r := b.doBench(nHint)
-                       if j == 0 {
-                               nHint = b.N
-                       }
+                       r := b.doBench()
                        if b.failed {
                                // The output could be very long here, but probably isn't.
                                // We print it all, regardless, because we don't want to trim the reason