I'm mucking around with the beta of the IBM Swift Sandbox; does anyone know why I'm getting the following error for the code below?:
LLVM ERROR: Program used external function 'CFAbsoluteTimeGetCurrent' which could not be resolved!
// A demonstration of both iterative and recursive algorithms for computing the Fibonacci numbers.
import CoreFoundation
// A recursive algorithm to compute the Fibonacci numbers.
func fibRec (n : Int) -> Double {
return (Double)(n < 3 ? 1 : fibRec(n - 1) + fibRec(n - 2))
}
// An iterative algorithm to compute the Fibonacci numbers.
func fibIter (n : Int) -> Double {
var f2 = 0.0
var f1 = 1.0
var f0 = 1.0
for _ in 0 ..< n {
f2 = f1 + f0
f0 = f1
f1 = f2
}
return f0
}
// Initialise array to hold algorithm execution times.
var fibTimes = [Double]()
// i is the ith Fibonacci number to be computed.
for i in 120..<129 {
var fibNum = 0.0
var fibSum = 0.0
// j is the number of times to compute F(i) to obtain average.
for j in 0..<5 {
// Set start time.
let startTime = CFAbsoluteTimeGetCurrent()
// Uses the recursive algorithm.
// fibNum = fibRec(i)
// Uses the iterative algorithm.
fibNum = fibIter(i)
fibTimes.insert(CFAbsoluteTimeGetCurrent() - startTime, atIndex: j)
}
// Compute the average execution time.
for p in fibTimes {
fibSum += p
}
fibSum = fibSum / 5
print("Fibonacci number \(i) is: \(fibNum)")
print("Execution time: \(fibSum) seconds")
}