English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Mini ray tracer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-05-04 (07:27)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Re: Mini ray tracer
On Wednesday 04 May 2005 07:24, Florian Hars wrote:
> I did some comparisions (the ml code on that page doesn't compile, but the
> fix is trivial) and told gcc 3.3.5 to actually optimize the c++ (-O2
> -march=x86-64 -msse2 -ffast-math)

As I said last night, my timings were for optimised C++ and optimised OCaml on 

> and the c++ was consistently faster than 
> the ocaml code for detail levels of 4 and greater, marginally at 4, about
> 20% at a level of 10, twice as fast at 12, and infinitely faster at a level
> of 14 (the c++ program finished in less than three minutes, the ocaml
> program started to trigger the oom killer after about an hour, and I
> finally had to push the friendly red button labeled "reset" to get my
> computer back).

Yes, the OCaml program seems to use ~50% more memory. I assume C++ is inlining 
those structs. It would be ugly to work around this in the OCaml, AFAIK. If 
you want to work at the extremes of memory usage then you'll probably want to 
ditch that data structure and use a single-precision float big array.

> This looks like a suboptimal example for the speed of ocaml.

These results appear to be specific to 64-bit.

As far as the shootout is concerned, we seem to have agreed that you can 
optimise your code up to 100 LOC. So the OCaml can have some algorithmic 
optimisations which increase its performance and verbostity.

With these algorithmic optimisations, I get 35.6s (82 LOC OCaml) vs 36.8s (92 
LOC C++) on AMD64 for n=11.

The optimisation is to trace shadow rays using an intersection routine which 
returns as soon as any intersection is found, rather than returning the 
parameter of the first intersection.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists