# Efficient implementations of Fibonacci function with interesting results

**URL:** <https://discourse.julialang.org/t/efficient-implementations-of-fibonacci-function-with-interesting-results/18123>\
**Category:** Numerics\
**Created:** [November 29, 2018, 1:34am UTC](https://discourse.julialang.org/t/efficient-implementations-of-fibonacci-function-with-interesting-results/18123 "2018-11-29T01:34:52Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 29, 2018, 4:02am UTC](https://discourse.julialang.org/t/efficient-implementations-of-fibonacci-function-with-interesting-results/18123/5 "2018-11-29T04:02:36Z")

</div>

The fastest method in Julia is probably to call the [optimized C implementation](https://github.com/alisw/GMP/blob/cc09e59afe9a23de9e7d0ef10598a395d7e8c850/mpz/fib_ui.c) from the underlying `libgmp` library:

```julia
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)!

---

_[View the full topic](https://discourse.julialang.org/t/efficient-implementations-of-fibonacci-function-with-interesting-results/18123)._
