Skip to content

Commit 31ad583

Browse files
josharianmpvl
authored andcommitted
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 <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 392bf3a commit 31ad583

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/testing/benchmark.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,9 @@ func (b *B) launch() {
263263
for n := 1; !b.failed && b.duration < d && n < 1e9; {
264264
last := n
265265
// Predict required iterations.
266-
if b.nsPerOp() == 0 {
267-
n = 1e9
268-
} else {
269-
n = int(d.Nanoseconds() / b.nsPerOp())
266+
n = int(d.Nanoseconds())
267+
if nsop := b.nsPerOp(); nsop != 0 {
268+
n /= int(nsop)
270269
}
271270
// Run more iterations than we think we'll need (1.2x).
272271
// Don't grow too fast in case we had timing errors previously.

0 commit comments

Comments
 (0)