Erlang Efficiency quesitons

Bjorn Gustavsson <>
Wed Mar 14 20:06:58 CET 2001

Ulf Wiger <> writes:

> On Wed, 14 Mar 2001, James Hague wrote:
> >> I also know that higher-order functions are very efficient now. This
> >> also means that old warnings about list comprehensions are no longer
> >> quite as valid.
> >
> >Does that only apply to list comprehensions? It seems, from doing some
> >timings, that just writing raw Erlang to process a list is still
> >significantly faster than doing a map or fold, for example.
> The significance depends on what your function does with the list
> elements. Let's say that it's considerably less significantly faster
> than it used to be.  ;-)

I've some benchmarks results:

(Read more about on my home page:
and download the source code for my benchmark suite.)

The rightmost column for the benchmark module call_bm shows the
relative times for different types of calls for OTP R6.
(Times are similar in R7.)

The fastet call is a local call. Its cost is 1.00.

An external call is slightly slower. Its cost is 1.19.
(Externall calls was horrible expensive in the pre-historic Beam R2 -
almost 16 times slower than a local call.)

The cost to a fun call is 3.13 that of a local call. In previous
version of Beam it used to be about 10 times slower than a local call.

Applying a fun is slightly slower (because the arguments are passed
in a list). The cost is 4.17.

Finally, the slowest call of all is apply(M, F, A), whose cost is 7.42.

In R8, funs will be slightly faster. List comprehensions will be
compiled to local functions, meaning that they will be as fast as
an hand-written (recursive) function.

A future version of the compiler will probably inline calls to
lists:map/2 and friends.


> /Uffe
> -- 
> Ulf Wiger                                    tfn: +46  8 719 81 95
> Senior System Architect                      mob: +46 70 519 81 95
> Strategic Product & System Management    ATM Multiservice Networks
> Data Backbone & Optical Services Division      Ericsson Telecom AB

Björn Gustavsson            Ericsson Utvecklings AB
			    BOX 1505
+46 8 727 56 87 	    125 25 Älvsjö

More information about the erlang-questions mailing list