[erlang-questions] Erlang shows its slow face!
Sun Nov 14 11:55:28 CET 2010
On 14 nov 2010, at 10.17, Hynek Vychodil wrote:
> Good idea but it seems that native (HiPE) compiler does this
> optimization for you when you keep staying in one module. (I also
> keeps exporting only main function. It can possibly take effect here
> also.) In BEAM it gives you 50% performance gain. Anyway Erlang is not
> right tool for this job. You should use NIF if performance matter.
> pythag4(N) when is_integer(N) -> pythag4(N,1).
I have implemented several small Erlang programs that beat "native" C code.
Most of the time the C programs where badly/hastily written, but that is the point ;-)
You must select the algorithm and the implementation wisely, and of course
use the golden rule "Make it work, then make it fast". I would add, if it is needed.
This does not imply that you should write your program unnecessary slow to start with!
Any how. A couple of months ago I implemented the AKS algorithm in Erlang.
The AKS algorithm is a deterministic primality test algorithm (http://en.wikipedia.org/wiki/AKS_primality_test)
I benchmarked this implementation with an implementation in C++.
I was shocked: The Erlang version was about 5 times faster, NOT using obvious parallelism.
In this case I would suspect that garbage collection is the major contributor! The implementation use
a lot of temporary polynomials intermediate results. A copy collector does the trick.
"Have run Make so many times I dunno what's installed anymore"
More information about the erlang-questions