THE SPEED OF SML/NJ
The speed of SML/NJ
As a programmer I am very concerned about the execution speed of the software
that I write. This is becuase that I don't like that a lot of software today tend
to get increasingly slower as computers get faster. When prgramming in a language
like Standard ML, the software is supposed to have very few bugs becuase of the
typesafety of the language. While I think this is an extremely Good Thing (TM),
I still don't think it is worth it, if the execution speed decreases too much.
This is the reason that I have made 2 tests on the performance of Standard ML.
My tests are done with
SML/NJ,
becuase this is a very complete SML system which is free and comes with sourcecode.
- The first test was to generate a datastructure of a 3D-sphere with
400.000 vertices. The datastructure was generated by setting up a new matrix
of 3D-rotate operations per vertex.
- The other test was to take a simpler 3D-sphere, and animate it by
applying a matrix transformation to all vertices in the sphere. Animation
was achieved by generating a new matrix for every image in the animation.
The matrix transformations was done in realtime and the 3D-sphere was drawn
as lines to form an animated wireframe display.
I compared the performance with 2 similar tests in Objective-C which I had created
earlier. It was compiled with GNU Objective-C with the -O2 option and compiled
for the Pentium CPU in my computer. The Objective-C code doesn't have many
method-calls (Objective-C messages), it's mostly ANSI-C. I ported from
Objective-C to SML, not vice versa, and even implemented the SML version
using the same code structure as the Objective-C version to be realistic.
I believe that the SML version can be done more efficiently when taking full
advantage of the features in SML.
The SML tests executed between half as fast and as fast as the Objective-C version,
except for sin/cos calls. I discovered that the sin/cos functions in SML/NJ are quite
inefficient compared to those in the GNU-C compiler.
I also tried to alter the first test to allocate and free the matrix object for each vertex.
This showed me that allocating/freeing modules in SML/NJ is a lot faster than
allocating/freeing objects in Objective-C.
SML compilers seems to be getting more efficient all the time as new compiler
technologies are invented. With this in mind and with the above test results,
I think I'm ready to start using SML for serious work.
Links to SML compilers