Skip to content

Commit 6ef5908

Browse files
committed
benchmarks: fix the Fibonacci and Ackermann benchmarks
The `getFalse` utility function was not excluded from cross-module-optimization, which led the optimizer to completely eliminate the main loop body Also, the passed `N` was shadowed by a local `n`.
1 parent 3daa875 commit 6ef5908

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

benchmark/single-source/Ackermann.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import TestsUtils
1616

1717
public let benchmarks =
1818
BenchmarkInfo(
19-
name: "Ackermann",
19+
name: "Ackermann2",
2020
runFunction: run_Ackermann,
2121
tags: [.algorithm])
2222

@@ -39,10 +39,10 @@ func ackermann(_ m: Int, _ n : Int) -> Int {
3939
let ref_result = [5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069]
4040

4141
@inline(never)
42-
public func run_Ackermann(_ n: Int) {
42+
public func run_Ackermann(_ N: Int) {
4343
let (m, n) = (3, 6)
4444
var result = 0
45-
for _ in 1...n {
45+
for _ in 1...N {
4646
result = ackermann(m, n)
4747
if result != ref_result[n] {
4848
break

benchmark/single-source/Fibonacci.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TestsUtils
1414

1515
public let benchmarks =
1616
BenchmarkInfo(
17-
name: "Fibonacci",
17+
name: "Fibonacci2",
1818
runFunction: run_Fibonacci,
1919
tags: [.algorithm])
2020

@@ -34,11 +34,11 @@ func fibonacci(_ n: Int) -> Int {
3434
}
3535

3636
@inline(never)
37-
public func run_Fibonacci(_ n: Int) {
37+
public func run_Fibonacci(_ N: Int) {
3838
let n = 24
3939
let ref_result = 46368
4040
var result = 0
41-
for _ in 1...n {
41+
for _ in 1...N {
4242
result = fibonacci(n)
4343
if result != ref_result {
4444
break

benchmark/utils/TestsUtils.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ public func autoreleasepool<Result>(
307307
}
308308
#endif
309309

310+
@_semantics("optimize.no.crossmodule")
310311
public func getFalse() -> Bool { return false }
311312

312313
@available(*, deprecated, renamed: "getFalse()")

0 commit comments

Comments
 (0)