Make benchmarks more reliable by using the scale factor (#539)

### Motivation:

Currently the benchmark machinery overhead is causing a lot of noise in
benchmarks of very efficient/fast code.

### Modifications:

Use the scaling factor to amortize the fixed overhead and let the actual
tested code account for most of the measured metrics.

### Result:

More reliable benchmarks that don't fail 20% of the time.
This commit is contained in:
Honza Dvorsky authored and GitHub committed 2026-11-19 09:59:58 +00:00
1 parent c7413d967b
commit d05c8efdae
47 files changed
+92 -87

No files matched your search

@@ -36,6 +36,7 @@ public func makeBenchmark(
"\(logLevel)_log_with_\(loggerLevel)_log_level\(suffix)",
configuration: .init(
metrics: metrics,
scalingFactor: .kilo,
maxIterations: iterations,
thresholds: [
.instructions: BenchmarkThresholds(
@@ -54,12 +55,16 @@ public func makeBenchmark(
if setScopedLogger {
withLogger(logger) { logger in
benchmark.startMeasurement()
body(logger)
for _ in benchmark.scaledIterations {
body(logger)
}
benchmark.stopMeasurement()
}
} else {
benchmark.startMeasurement()
body(logger)
for _ in benchmark.scaledIterations {
body(logger)
}
benchmark.stopMeasurement()
}
}