Skip to content

Commit 42b2639

Browse files
palimondoDavide Italiano
authored andcommitted
[benchmark] Gardening: Documentation of numIters
Clarified the need for capping `numIters` according to the discussion at #17268 (comment) The sampling loop is a hairy piece of code, because it’s trying to reuse the calibration measurement as a regular sample, in case the computed `numIters` turns out to be 1. But it conflicts with the case when `fixedNumIters` is 1, necessitating a separate measurement in the else branch… That was a quick fix back then, but its hard to make it clean. More thinking is required…
1 parent eacfce8 commit 42b2639

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

benchmark/utils/DriverUtils.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,27 +429,26 @@ func runBench(_ test: BenchmarkInfo, _ c: TestConfig) -> BenchResults? {
429429
var numIters : Int
430430
var time: Int = 0
431431
if c.fixedNumIters == 0 {
432+
// Compute the `numIters` if a `c.fixedNumIters` is not specified.
432433
time = sampler.measure(test.name, fn: testFn, numIters: 1)
433434

434435
if time > 0 {
435436
let usPerSecond = 1_000_000.0 // microseconds (μs)
436437
let timePerSample = Int(c.sampleTime * usPerSecond)
437-
/// Number of iterations to make `testFn` run for the desired time.
438+
// Number of iterations to make `testFn` run for the desired time.
438439
numIters = timePerSample / time
439440
} else {
440441
logVerbose(" Warning: elapsed time is 0!")
441442
numIters = 1
442443
}
443444
} else {
444-
// Compute the scaling factor if a fixed c.fixedNumIters is not specified.
445445
numIters = c.fixedNumIters
446446
if numIters == 1 {
447447
time = sampler.measure(test.name, fn: testFn, numIters: 1)
448448
}
449449
}
450-
// Make integer overflow less likely on platforms where Int is 32 bits wide.
451-
// FIXME: Switch BenchmarkInfo to use Int64 for the iteration scale, or fix
452-
// benchmarks to not let scaling get off the charts.
450+
// Cap the `numIters` to prevent overflow on 32-bit systems during
451+
// multiplication with the inner loop multiplier inside the `testFn`.
453452
numIters = min(numIters, Int.max / 10_000)
454453

455454
// Rerun the test with the computed scale factor.

0 commit comments

Comments
 (0)