diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2016-06-25 15:11:25 -0700 |
---|---|---|
committer | Marcel van Lohuizen <mpvl@golang.org> | 2016-08-10 19:44:08 +0000 |
commit | 31ad583ab24263f9dbcb5cbcce849eed64e74040 (patch) | |
tree | 97cbf4ca8e508b91487b8d94acec85c2a5245053 | |
parent | 392bf3a9cfee297ec106d5a67c37d8edb4c8c183 (diff) | |
download | go-31ad583ab24263f9dbcb5cbcce849eed64e74040.tar.gz go-31ad583ab24263f9dbcb5cbcce849eed64e74040.zip |
testing: respect benchtime on very fast benchmarks
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>
-rw-r--r-- | src/testing/benchmark.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go index 5d58b85e78..4d45130516 100644 --- a/src/testing/benchmark.go +++ b/src/testing/benchmark.go @@ -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. |