« September 6, 2017 | Main | September 12, 2017 »

Saturday, September 9, 2017

Floating Point Benchmark: Scala Language Added

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

Scala is a general purpose programming language originally developed at the École Polytechnique Fédérale in Lausanne, Switzerland. Scala combines the paradigm of functional programming with support for conventional object-oriented imperative programming, allowing the programmer to choose whichever style is most expressive of the algorithm being implemented. Unlike Haskell, which forces the programmer into a strict functional style, Scala contains control structures for iteration, mutable variables, and a syntax which C and Java programmers will find familiar. Scala runs on the Java virtual machine, and Scala and Java code can interoperate, which provides Scala access to all existing Java libraries.

The Scala version of the benchmark was developed and tested using Scala 2.12.3 on an x86_64 machine running Xubuntu 16.04 kernel 4.4.0-93. In order to compile and run this program you must install Scala on your computer.

Scala programs compile to byte code which is executed by an implementation of the Java virtual machine. I ran these tests using:

openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

The Scala implementation of the floating point benchmark is written mostly in a pure functional style, but I did use mutable variables and iteration where it made the code more readable. Scala does not optimise tail recursion as aggressively as Haskell, so iteration may be more efficient in heavily-used code.

At the time I developed this benchmark, a recent release of the GNU C mathematical function library had been issued which halved the mean execution speed of trigonometric functions. This made all comparisons of run time against the C reference implementation of the benchmark using the earlier, more efficient libraries, invalid. (It's said that the performance hit was done in the interest of improved accuracy, but it made no difference in the computations of the floating point benchmark, which are checked to 13 significant digits.) Consequently, I compared the execution speed of the Scala implementation against that of the Java version, then computed the speed relative to the original C version with the old libraries by multiplying the relative speed of Java vs. C and Scala vs. Java.

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
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
Free Pascal 2.2.0 -O3, Linux
GNU Pascal 2.1 (GCC 2.95.2) -O3, Linux
Swift 1.054 Swift 3.0.1, -O, Linux
Rust 1.077 Rust 0.13.0, --release, 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
Scala 1.263 Scala 2.12.3, OpenJDK 9, 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
Lua 2.515
LuaJIT 2.0.3, Linux
Lua 5.2.3, Linux
Python 2.633
PyPy 2.2.1 (Python 2.7.3), Linux
Python 2.7.6, Linux
Erlang 3.663
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
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
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
Perl 23.6 Perl v5.8.0, Linux
Ruby 26.1 Ruby 1.8.3, Linux
JavaScript 27.6
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
Mathematica 391.6 Mathematica, Raspberry Pi 3, Raspbian

Posted at 13:38 Permalink