Erlang array access benchmark

James Hague jamesh@REDACTED
Mon Jun 18 21:24:03 CEST 2001


I was perusing Doug Bagley's language shootout page a few evenings ago and
noticed that there wasn't an Erlang entry for the Array Access benchmark.
Not too surprising, given the state of array handling in Erlang, but I
decided to give it a go anyway.

My first submitted attempt used the process dictionary for the two arrays.
The code was succinct, but the performance was horrible.  The run-time of 40
seconds put it in the same ballpark as TCL.

Then I rewrote it using ETS tables.  As the benchmark was based around
adding values into an array, I could use ets:update_counter, which was nice.
Version 2 almost doubled the performance of version 1, clocking in at 22
seconds, better than guile and Ruby, but still behind ghc (a machine code
generating Haskell compiler).

Over the weekend I realized that only one array was being written into and
the other was simply used for heavy indexing.  So I initialized that array
as a list, then converted it to a tuple.  The other array was still an ets
table.  This doubled the performance again, dropping the execution time to
ten seconds.  In the process, Erlang passed ghc, Icon, Python, Perl, and
Lua.

Sure, Erlang is still 90 times slower than the C entry, but it was fun
helping it slide up the scale a bit :)  It is also interesting that for
something as un-Erlang-like as array access, Erlang still fared better than
Python and Perl.

James



More information about the erlang-questions mailing list