[erlang-questions] Blog: Erlang Fractal Benchmark

Bjorn Gustavsson bjorn@REDACTED
Tue Jun 5 09:56:30 CEST 2007


"Jim Menard" <jim.menard@REDACTED> writes:

> On 6/4/07, Ulf Wiger (TN/EAB) <ulf.wiger@REDACTED> wrote:
> >
> > I ran it on my machine, which scored a miserable
> > 4.2 seconds. Adding is_float/1 guards around all
> > variables that are floats (quite a few) and
> > compiling with native brought it down to 1.8 secs.
> 
> It sped up my version considerably as well. Why is that? I thought
> that a guard clause was only used to select which function clause to
> run. How does checking to see if something is a float make things
> faster instead of slowing it down by having to execute is_float/1 for
> each call?

Because the compiler can generate specially optimized code that only handles
floating point arithmetic, instead of the standard arithmetic instructions
that can handle both integer and floating point arithmetic.

/Björn
-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list