# Simple recursive Fibonaci example. How to make it faster?

**URL:** <https://discourse.julialang.org/t/simple-recursive-fibonaci-example-how-to-make-it-faster/32369>\
**Category:** Performance\
**Created:** [December 17, 2019, 2:59am UTC](https://discourse.julialang.org/t/simple-recursive-fibonaci-example-how-to-make-it-faster/32369 "2019-12-17T02:59:46Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 17, 2019, 3:42pm UTC](https://discourse.julialang.org/t/simple-recursive-fibonaci-example-how-to-make-it-faster/32369/15 "2019-12-17T15:42:16Z")

</div>

As noted above, it is probably TCO and/or unrolling.

We can also do all kinds of tricks, eg

```julia
function fibval(::Val{N}) where N
    if N ≤ 1
        1
    else
        fibval(Val{N - 1}()) + fibval(Val{N - 2}())
    end
end

julia> @time fibval(Val(46)) # first run, includes complilation time
  0.057667 seconds (166.50 k allocations: 9.972 MiB, 22.78% gc time)

julia> @time fibval(Val(46)) # let's benchmark Base.show
  0.000182 seconds (4 allocations: 160 bytes)

```

These things are fun, but they tell you little about real-life performance of 10K LOC applications, which is what matters in practice — and of course, developer time.

---

_[View the full topic](https://discourse.julialang.org/t/simple-recursive-fibonaci-example-how-to-make-it-faster/32369)._
