What about Fortran for speed
As I was playing with fibonacci sequences to try different languages I decided to return to one of my first/oldest/smelliest languages: fortran.
I coded a recursive function like this:
program fibonacci
implicit none
integer :: fibo
print *, "Fibonacci 44:", fibo(44)
end program
recursive integer function fibo(n) result(a)
if (n<2) then
a = n
else
a = fibo(n-2)+fibo(n-1)
end if
end function fibo
You can compare this to the C Version and think that these two will be similar.
Until when they are compiled. With no optimization their runnig times arem comparable, but when using -O2 the fortran version smokes the C version. 1.0s vs 1.9s in my MBAir. What? I expected them to be on parity but we are always surprised.
Other versions of fibo are on github.