]> Cypherpunks.ru repositories - gostls13.git/commitdiff
testing: respect benchtime on very fast benchmarks
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 25 Jun 2016 22:11:25 +0000 (15:11 -0700)
committerMarcel van Lohuizen <mpvl@golang.org>
Wed, 10 Aug 2016 19:44:08 +0000 (19:44 +0000)
When ns/op dropped below 1, the old code
ignored benchtime and reverted to 1s.

Change-Id: I59752cef88d8d73bfd5b085f5400ae657f78504e
Reviewed-on: https://go-review.googlesource.com/26664
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
src/testing/benchmark.go

index 5d58b85e78a2ebb16c65327e90d35e08758865a6..4d4513051611a5b89a11620df71a54ce5ee2723f 100644 (file)
@@ -263,10 +263,9 @@ func (b *B) launch() {
        for n := 1; !b.failed && b.duration < d && n < 1e9; {
                last := n
                // Predict required iterations.
-               if b.nsPerOp() == 0 {
-                       n = 1e9
-               } else {
-                       n = int(d.Nanoseconds() / b.nsPerOp())
+               n = int(d.Nanoseconds())
+               if nsop := b.nsPerOp(); nsop != 0 {
+                       n /= int(nsop)
                }
                // Run more iterations than we think we'll need (1.2x).
                // Don't grow too fast in case we had timing errors previously.