[Haskell-cafe] Haskell version of ray tracer code is much slower than the original ML

Jon Harrop jon at ffconsultancy.com
Thu Jun 21 08:39:24 EDT 2007

Awesome stuff!

On Thursday 21 June 2007 12:36:27 Philip Armstrong wrote:
> On Thu, Jun 21, 2007 at 12:25:44PM +0100, Sebastian Sylvan wrote:
> >Try using floats for the vector, and strict fields (add a ! to the
> >fields in the data declaration).
> Because the optimisation page on the haskell wiki is very explicit
> about never using Float when you can use Double, that's why. An older
> revision used Float and it was slower than the current one. Making the
> datatypes strict also makes no difference.

Where exactly do the !s go and what do they do?

> >That's the simplest possible thing I can think of after about two
> >seconds of looking anyway. It appears that the ML version uses float
> >so I don't understand why you would use Double for the Haskell version
> >at all, and then think you could do any sort of valid comparisons
> >between them...
> OCaML floats are Doubles, at least on x86.

Yes. OCaml doesn't have a 32-bit float storage format, apart from an 
entirely-float big array. Also, the ML in OCaml doesn't stand for 
metalanguage. ;-)

There is probably some benefit to laziness in this example because many of the 
spheres are occluded in the final image, so parts of the scene tree that are 
eagerly generated in the other implementations may actually never be 
traversed by the renderer.

I take it you saw the whole language comparison:


I'll be uploading concurrent implementations ASAP. Haskell should do well 
there... :-)

PS: You spelled my name wrong!
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal

More information about the Haskell-Cafe mailing list