mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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`.
This commit is contained in:
@@ -16,7 +16,7 @@ import TestsUtils
|
||||
|
||||
public let benchmarks =
|
||||
BenchmarkInfo(
|
||||
name: "Ackermann",
|
||||
name: "Ackermann2",
|
||||
runFunction: run_Ackermann,
|
||||
tags: [.algorithm])
|
||||
|
||||
@@ -39,10 +39,10 @@ func ackermann(_ m: Int, _ n : Int) -> Int {
|
||||
let ref_result = [5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069]
|
||||
|
||||
@inline(never)
|
||||
public func run_Ackermann(_ n: Int) {
|
||||
public func run_Ackermann(_ N: Int) {
|
||||
let (m, n) = (3, 6)
|
||||
var result = 0
|
||||
for _ in 1...n {
|
||||
for _ in 1...N {
|
||||
result = ackermann(m, n)
|
||||
if result != ref_result[n] {
|
||||
break
|
||||
|
||||
@@ -14,7 +14,7 @@ import TestsUtils
|
||||
|
||||
public let benchmarks =
|
||||
BenchmarkInfo(
|
||||
name: "Fibonacci",
|
||||
name: "Fibonacci2",
|
||||
runFunction: run_Fibonacci,
|
||||
tags: [.algorithm])
|
||||
|
||||
@@ -34,11 +34,11 @@ func fibonacci(_ n: Int) -> Int {
|
||||
}
|
||||
|
||||
@inline(never)
|
||||
public func run_Fibonacci(_ n: Int) {
|
||||
public func run_Fibonacci(_ N: Int) {
|
||||
let n = 24
|
||||
let ref_result = 46368
|
||||
var result = 0
|
||||
for _ in 1...n {
|
||||
for _ in 1...N {
|
||||
result = fibonacci(n)
|
||||
if result != ref_result {
|
||||
break
|
||||
|
||||
@@ -307,6 +307,7 @@ public func autoreleasepool<Result>(
|
||||
}
|
||||
#endif
|
||||
|
||||
@_semantics("optimize.no.crossmodule")
|
||||
public func getFalse() -> Bool { return false }
|
||||
|
||||
@available(*, deprecated, renamed: "getFalse()")
|
||||
|
||||
Reference in New Issue
Block a user