Product of consecutive Fib numbers - how to cache?

There is an updated version that improved the performance of the Map version:

  • Fib.ets/2: 23.314 ms
  • Fib.mem/2: 23.493 ms
  • Fib.lco/1: 26.574 ms

Essentially adding a value at a time with Map.put/3 was too slow. It was faster to collect all the new values as key value pairs in a list and add them all at once with :maps.merge/2.

new_mem =
  kvs
  |> :maps.from_list(kvs)
  |> :maps.merge(mem)

fprof