[erlang-questions] Erlang arithmetics

Masklinn masklinn@REDACTED
Sat Oct 30 10:59:51 CEST 2010


On 2010-10-30, at 10:03 , Dmitry Demeshchuk wrote:
> 
> 1. I've done something wrong and my tests suck (but that may mean that
> the difference in performance may be even more significant)
> 2. Erlang uses type overflow check on each computation to determine if
> it's time to switch from smallint to bigint.
> 3. Some more reasons that I don't know about or don't consider.

Might not be all of it, but I'll go with third for now: you haven't indicated which Erlang runtime you're using (or your compilation options), so I can only assume it's the BEAM interpreter.

V8 is based on a quite modern JIT, and even fairly trivial JITs are extremely efficient on highly repetitive, highly-numerical code[0], and will therefore perform very, very well on your code which is precisely that. BEAM, on the other hand, is a fairly basic interpreter, and the overhead of numerical code is therefore quite large compared to a JIT.

I would suggest first checking you're using HiPE.

[0] Python's third-party JIT, Psyco, will usually net a 2-4x speedup on "normal" Python code (at the cost of memory), but in algorithmical, numerical code the gains are generally above 10x and can reach two orders of magnitude (100x). You can also see this effect when comparing PyPy with CPython [1]

[1] PyPy is a complete Python reimplementation using, among other things, a JIT (which CPython doesn't). In the Alioth shootout[2], the difference between numerical tests and string-based ones is flagrant: PyPy is 4 times faster than CPython on fannkuch-redux or spectral-norm but 10 times slower on reverse-complement or regex-dna (using the exact same code) [3]

[2] http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=pypy&lang2=python 

[3] pidigits doesn't count, as the CPython version uses gmpy


More information about the erlang-questions mailing list