A simple module to perform Fibonacci computation in the Elixir language.
I am not a great fan of mathematic, but the sequence of Fibonacci is a good work horse to stress computation via recursive logic with any programming language.
This version does not attempt to perform tail-recursion, which indeed is optimized by some (BEAM) virtual machines (for an elegant solution look here). Instead it relies on multiprocessing and memoization by using the Agent and Task abstractions in the Elixir base library.
Computation without cache starts struggling when reaching numbers near 30 (MacBook Pro i7 2.2Ghz 8GB). Memoized version is a blaze, but trades speed for memory consumption.
The use of the library is pretty straightforward:
1..10 |> Enum.map &Fibonacci.of/1
For the cached version remember to initialize the Agent:
Fibonacci.cache_start
Fibonacci.of 10000