Efficient implementations of Fibonacci function with interesting results

The fastest method in Julia is probably to call the optimized C implementation from the underlying libgmp library:

function fastfib(n)
    z = BigInt()
    ccall((:__gmpz_fib_ui, :libgmp), Cvoid, (Ref{BigInt}, Culong), z, n)
    return z
end

This is about 50% faster than your memo-ized fib implementation above (which means your fib function is quite good)!

7 Likes