[Shootout-list] Erlang fibonacci
Einar Karttunen
ekarttun@cs.helsinki.fi
Sun, 13 Jun 2004 19:16:12 +0300
Hello
The following should produce fibonacci faster in the same naive way
*with* bytecode interpreter. The original is faster for the native case.
fib2(0) -> 1;
fib2(1) -> 1;
fib2(N) -> fib2(N-2) + fib2(N-1).
Native compilation would make things really faster here (almost five
times). Here is a short benchmark of the differences:
27> timer:tc(fib, fib1, [20]).
{1416,10946}
28> c(fib, [native, {hipe, [o3]}]).
{ok,fib}
29> timer:tc(fib, fib1, [20]).
{286,10946}
286 vs 1416 is a quite large difference...
- Einar Karttunen