7 ms·
The first 40 Fibonacci numbers are calculated on my laptop under 5 milliseconds using the Erlang code below, i.e. more then 2000 times faster then his measured
by babo 18y ago
The first 40 Fibonacci numbers are calculated on my laptop under 5 milliseconds using the Erlang code below, i.e. more then 2000 times faster then his measured 10.xxx second on an 8 core server. Erlang has an edge for sure, but you need to implement that few lines in a proper and efficient way to prove it and a meaningful test is a must.
ffib(0) -> [0];
ffib(1) -> [0, 1];
ffib(N) when N > 0 -> ffib([1, 1, 0], 2, N).
ffib(R, N, N) -> lists:reverse(R);
ffib([H1, H2 | _] = Prev, C, N) ->
ffib([H1+H2 | Prev], C+1, N).