Skip to content

Commit fb541ad

Browse files
authored
Merge pull request swiftlang#17268 from lorentey/benchmark32
Fix benchmark suite on 32-bit platforms
2 parents 02eaf61 + d66d6b4 commit fb541ad

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

benchmark/single-source/RandomValues.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public func run_RandomIntegersDef(_ N: Int) {
5454
@inline(never)
5555
public func run_RandomIntegersLCG(_ N: Int) {
5656
for _ in 0 ..< N {
57-
var x = 0
57+
var x: Int64 = 0
5858
var generator = LCRNG(seed: 0)
5959
for _ in 0 ..< 100_000 {
60-
x &+= Int.random(in: 0...10_000, using: &generator)
60+
x &+= Int64.random(in: 0...10_000, using: &generator)
6161
}
6262
CheckResults(x == 498214315)
6363
}

benchmark/utils/DriverUtils.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ func runBench(_ test: Test, _ c: TestConfig) -> BenchResults? {
403403
// Compute the scaling factor if a fixed c.fixedNumIters is not specified.
404404
scale = c.fixedNumIters
405405
}
406+
// Make integer overflow less likely on platforms where Int is 32 bits wide.
407+
// FIXME: Switch BenchmarkInfo to use Int64 for the iteration scale, or fix
408+
// benchmarks to not let scaling get off the charts.
409+
scale = min(scale, UInt(Int.max) / 10_000)
406410

407411
// Rerun the test with the computed scale factor.
408412
if scale > 1 {

0 commit comments

Comments
 (0)