« Reversing Myopia |
| Reading List: Down with Power »
Tuesday, October 9, 2012
Floating Point Benchmark: Forth Language Added
I have posted an update to my trigonometry-intense floating point benchmark
to the list of languages in which the benchmark is implemented. A new release of the
including Forth is now available for downloading.
The Forth benchmark was developed using Gforth
0.7.0. Care was taken to use only ANS Forth
in the implementation; the following word sets are used in the program:
Editing of floating point numbers is done with a stripped-down version of the fpout17
library linked on the Gforth Links to Forth programs
page. The author of this program is identified only as “Ed”, and the source code indicates it is in the public domain. I have stripped out all functionality not required by the benchmark and changed some names to avoid redefinition warnings in some Forth systems. Ed, if I knew who you were, I'd buy you a beer—this code saved me a great deal of tedious work.
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.
||GCC 3.2.3 -O3, Linux
|Visual Basic .NET
||All optimisations, Windows XP
||GNU Fortran (g77) 3.2.3 -O3, Linux
|Free Pascal 2.2.0 -O3, Linux
GNU Pascal 2.1 (GCC 2.95.2) -O3, Linux
||Sun JDK 1.5.0_04-b05, Linux
|Visual Basic 6
||All optimisations, Windows XP
||GHC 7.4.1-O2 -funbox-strict-fields, Linux
||GNAT/GCC 3.4.4 -O3, Linux
|GNU Common Lisp 2.6.7, Compiled, Linux
GNU Common Lisp 2.6.7, Interpreted
||GNU Smalltalk 2.3.5, Linux
||Gforth 0.7.0, Linux
|Micro Focus Visual COBOL 2010, Windows 7
Fixed decimal instead of computational-2
||Python 2.3.3 -OO, Linux
||Perl v5.8.0, Linux
||Ruby 1.8.3, Linux
|Opera 8.0, Linux
Internet Explorer 6.0.2900, Windows XP
Mozilla Firefox 1.0.6, Linux
||MS-DOS QBasic 1.1, Windows XP Console
The performance compared to native C code is consistent with my experience with ATLAST
more than two decades ago. There, I saw a speed penalty of a Forth-like language of between a factor of 5 and 8 compared to C code, whereas here it's around a factor of 10. But much has changed since then: optimisation of C code is much better, and we've moved from 16 bit segmented architectures to flat address spaces where native code has additional advantages compared to threaded code.
I also ran the benchmark under an evaluation version of Forth, Inc.'s SwiftForth
system. I do not report results in the table above because the output differed in the last decimal place due to apparent problems in rounding floating point numbers for display. (I did not investigate this—the problem may be an incompatibility in the floating point output editing code I used.) If you wish to repeat this experiment, you'll need to un-comment the indicated statements at the top of fbench.fs
and adjust the path for including the floating point library to where it is installed on your system. SwiftForth ran the benchmark around 14% slower than Gforth.
Please bear in mind that very few people do this kind of scientific computation in Forth—it is mostly used for device control and embedded software applications. Indeed, floating point came late to Forth, with fixed-point being the rule for most of the language's history. Consequently, this benchmark isn't remotely representative of the performance of most of the things people do in Forth. It is what it is—a benchmark more than thirty years old which was uncanny in its ability to determine how fast AutoCAD would run on a machine back in the day. Thinking about re-implementing AutoCAD in Forth?
Posted at October 9, 2012 21:52