Skip to content

Commit e5f3d7d

Browse files
committed
fixup: prevent roundN to be 0
1 parent db00ce3 commit e5f3d7d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

testing/testing/benchmark.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ func (b *B) launch() {
374374
benchD := time.Second * b.benchTime.d
375375
benchN := predictN(benchD.Nanoseconds(), int64(b.N), b.duration.Nanoseconds(), warmupN)
376376
rounds := 100 // TODO: Compute the rounds in a better way
377-
roundN := benchN / int(rounds)
377+
// Ensure roundN is at least 1 to prevent division by zero in BenchmarkResult printing
378+
// when very slow benchmarks can't complete even 1 iteration per round
379+
roundN := max(benchN/int(rounds), 1)
378380

379381
for range rounds {
380382
b.runN(int(roundN))

0 commit comments

Comments
 (0)