« June 13, 2014 | Main | June 22, 2014 »

Monday, June 16, 2014

Floating Point Benchmark: Erlang Language Added

I have posted an update to my trigonometry-intense floating point benchmark which adds Erlang to the list of languages in which the benchmark is implemented. A new release of the benchmark collection including Erlang is now available for downloading.

The Erlang programming language was originally developed by the Swedish telecommunication equipment manufacturer Ericsson. Its name is simultaneously a reference to the unit of circuit load used in circuit-switched communication systems, the Danish engineer after whom the unit is named, and an abbreviation for “Ericsson Language”. While originally a proprietary Ericsson product for in-house use, in 1998 the language and software was released as an open source product and is now distributed by erlang.org.

Erlang is intended to facilitate the implementation of concurrent, scalable, distributed, and high-availability systems of the kinds needed to support large telecommunication networks. Concurrency, based upon a message-passing architecture, is built into the language at a low level, as is support for symmetric multiprocessing, allowing Erlang programs to easily exploit modern multi-core microprocessors. A general port architecture allows moving components of a system among physical hardware without reprogramming, and fault tolerance allows the detection of errors and restarting modules which have failed. It is possible to “hot swap” components in running systems without taking the entire system down for the update.

The language adopts the functional programming model, although it is not as strict in enforcing this paradigm as Haskell. The language is dynamically typed, does not use lazy evaluation, allows input/output within functions not specially marked as having side effects, and has ways a sneaky programmer can store global state or create side effects. While these may seem to be (indeed, they are) compromises with a strict reading of functional programming, Erlang is clearly a tool created by practical programmers intended to be used to build very large production systems which have to keep running no matter what. It is not an academic project made to prove a point. (But then Haskell is very pure, and yet that has not kept large systems from being built using it.)

One advantage of choosing Erlang when building a system which may need to grow at a vertiginous rate from its original implementation is that it's “been there; done that”. Companies such as WhatsApp (messaging service), Facebook (chat service), and Goldman Sachs (high-frequency trading) all use Erlang. You may not be dealing with the most philosophically pure functional language, but one which has earned its chops in the real world.

The relative performance of the various language implementations (with C taken as 1) is as follows. All language implementations of the benchmark listed below produced identical results to the last (11th) decimal place.

Language Relative
Time
Details
C 1 GCC 3.2.3 -O3, Linux
Visual Basic .NET 0.866 All optimisations, Windows XP
FORTRAN 1.008 GNU Fortran (g77) 3.2.3 -O3, Linux
Pascal 1.027
1.077
Free Pascal 2.2.0 -O3, Linux
GNU Pascal 2.1 (GCC 2.95.2) -O3, Linux
Java 1.121 Sun JDK 1.5.0_04-b05, Linux
Visual Basic 6 1.132 All optimisations, Windows XP
Haskell 1.223 GHC 7.4.1-O2 -funbox-strict-fields, Linux
Ada 1.401 GNAT/GCC 3.4.4 -O3, Linux
Go 1.481 Go version go1.1.1 linux/amd64, Linux
Simula 2.099 GNU Cim 5.1, GCC 4.8.1 -O2, Linux
Erlang 3.663
9.335
Erlang/OTP 17, emulator 6.0, HiPE [native, {hipe, [o3]}]
Byte code (BEAM), Linux
ALGOL 60 3.951 MARST 2.7, GCC 4.8.1 -O3, Linux
Lisp 7.41
19.8
GNU Common Lisp 2.6.7, Compiled, Linux
GNU Common Lisp 2.6.7, Interpreted
Smalltalk 7.59 GNU Smalltalk 2.3.5, Linux
Forth 9.92 Gforth 0.7.0, Linux
COBOL 12.5
46.3
Micro Focus Visual COBOL 2010, Windows 7
Fixed decimal instead of computational-2
Algol 68 15.2 Algol 68 Genie 2.4.1 -O3, Linux
Python 17.6 Python 2.3.3 -OO, Linux
Perl 23.6 Perl v5.8.0, Linux
Ruby 26.1 Ruby 1.8.3, Linux
JavaScript 27.6
39.1
46.9
Opera 8.0, Linux
Internet Explorer 6.0.2900, Windows XP
Mozilla Firefox 1.0.6, Linux
QBasic 148.3 MS-DOS QBasic 1.1, Windows XP Console

By default, Erlang compiles to a machine-independent byte code which is executed by the runtime system. The developers say this is typically about ten times slower than C compiled to native code for computationally intense numeric and text processing work. My test confirmed this, with the byte code compiled benchmark running 9.3 times slower than C. On some platforms, including the GNU/Linux x86_64 machine on which I ran the benchmark, Erlang supports HiPE (High Performance Erlang), which allows compilation to native machine code. Using this option and specifying the highest level of optimisation produces a program which runs just 3.7 times slower than C. While this may seem a substantial penalty, it's worth noting that telecommunication systems rarely do serious number crunching or text shuffling: they're all about database accesses and intercommunication, and what is paramount is reliability, scalability, and the ability to distribute the application across multiple hardware platforms. Erlang's strengths in these areas may outweigh its greater CPU usage for large-scale distributed systems.

Posted at 23:37 Permalink