Bluish Coder

Programming Languages, Martials Arts and Computers. The Weblog of Chris Double.


2006-04-04

Factor and The Computer Language Shootout

I implemented one of the Computer Language Shootout benchmarks in Factor to see how it would compare. I wanted to get a gauge of the comparative performance of compiled Factor as well as seeing how the Factor implementations of the algorithms looked.

I started with the recursion benchmark. A darcs repository containing the Factor code and the C code for this can be obtained from the following command:

darcs get http://www.bluishcoder.co.nz/repos/computer-language-shootout

The Factor implementation is an almost direct translation of the C code.

To run the Factor code I created an image with the recursive.factor loaded and compiled:

./f factor.image -shell=tty
"recursive.factor" run-file
"recursive" words [ try-compile ] each
save

I then ran 'run-recursive.factor' which just calls the 'run' word in the recursive vocabulary and used the Unix 'time' command:

time ./f factor.image-shell=tty run-recursive.factor

The C code runs in 2.7 seconds with an argument of '11'. The Factor code runs in 31.8 seconds (it is hardcoded to use 11 as the argument). This is on my machine.

In the online recursive benchmarks the C code ran at 3.33 seconds. Assuming the speeds are relative this would mean that Factor would slot in at the benchmark at about 39.2 seconds ranking it slightly slower than GForth on the list.

The timing includes the starting up and relocating of the Factor image. Running the test within an already started image gives a 30.5 second runtime meaning the image startup takes about 1.3 seconds.

The code is written very much like the existing C code and I'll play around with it to see what a more concatenative style produces. Manfred Von Thun wrote an article on Nested Recursion for Joy that implemented Ackermann using a 'condnestrec' combinator. Trying a style like this in Factor to see the performance hit would be interesting.

Tags


This site is accessable over tor as hidden service mh7mkfvezts5j6yu.onion, or Freenet using key:
USK@1ORdIvjL2H1bZblJcP8hu2LjjKtVB-rVzp8mLty~5N4,8hL85otZBbq0geDsSKkBK4sKESL2SrNVecFZz9NxGVQ,AQACAAE/bluishcoder/-44/


Tags

Archives
Links