* Mini ray tracer
@ 2005-04-28 9:37 Jon Harrop
2005-05-02 19:48 ` Julian Brown
0 siblings, 1 reply; 6+ messages in thread
From: Jon Harrop @ 2005-04-28 9:37 UTC (permalink / raw)
To: caml-list
I just knocked up a little ray tracer in OCaml to test its viability for the
shootout:
http://www.ffconsultancy.com/free/ray_tracer/
Here, it traces a 768^2 image of 66,430 spheres in 22.51s on a 1.2GHz
Athlon-Thunderbird and in 7.24s on a 1.8GHz Athlon 64.
I've boiled it down to 94 LOC and posted it to the shootout mailing list.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Mini ray tracer
2005-04-28 9:37 Mini ray tracer Jon Harrop
@ 2005-05-02 19:48 ` Julian Brown
2005-05-03 22:47 ` [Caml-list] " Jon Harrop
2005-05-04 6:24 ` Florian Hars
0 siblings, 2 replies; 6+ messages in thread
From: Julian Brown @ 2005-05-02 19:48 UTC (permalink / raw)
To: caml-list
On 2005-04-28, Jon Harrop <jon@ffconsultancy.com> wrote:
>
> I just knocked up a little ray tracer in OCaml to test its viability for the
> shootout:
>
> http://www.ffconsultancy.com/free/ray_tracer/
>
> Here, it traces a 768^2 image of 66,430 spheres in 22.51s on a 1.2GHz
> Athlon-Thunderbird and in 7.24s on a 1.8GHz Athlon 64.
>
> I've boiled it down to 94 LOC and posted it to the shootout mailing list.
Re:
http://www.ffconsultancy.com/free/ray_tracer/comparison.html
Interesting results, but it's kind of unfair to leave optimisation turned
off for g++! What kind of results do you get with, say, -O3 -ffast-math?
Cheers,
Julian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Re: Mini ray tracer
2005-05-02 19:48 ` Julian Brown
@ 2005-05-03 22:47 ` Jon Harrop
2005-05-04 6:24 ` Florian Hars
1 sibling, 0 replies; 6+ messages in thread
From: Jon Harrop @ 2005-05-03 22:47 UTC (permalink / raw)
To: caml-list
On Monday 02 May 2005 20:48, Julian Brown wrote:
> Interesting results, but it's kind of unfair to leave optimisation turned
> off for g++! What kind of results do you get with, say, -O3 -ffast-math?
Sorry, I just misquoted the compile line, which really did have optimisations
on:
g++ -O2 -march=athlon-tbird ray.cpp -o ray
-O3 and -ffast-math make little difference (OCaml is still substantially
faster).
From my AMD64 results, it appears that g++ is having the floating point
problem that ocamlopt usually has. Specifically, it is producing very poor FP
performance on x86 but much better on AMD64.
Even more curiously, using single precision in the C++ version (which is
difficult to do in the OCaml version), the performance is vastly better on
x86 but vastly worse on AMD64?!? My uneducated guess is a float-align problem
but I haven't really looked into it.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Re: Mini ray tracer
2005-05-02 19:48 ` Julian Brown
2005-05-03 22:47 ` [Caml-list] " Jon Harrop
@ 2005-05-04 6:24 ` Florian Hars
2005-05-04 7:27 ` Jon Harrop
1 sibling, 1 reply; 6+ messages in thread
From: Florian Hars @ 2005-05-04 6:24 UTC (permalink / raw)
To: caml-list; +Cc: jon
Julian Brown wrote:
>> Re:
>
> http://www.ffconsultancy.com/free/ray_tracer/comparison.html
>
> Interesting results, but it's kind of unfair to leave optimisation turned
> off for g++!
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) 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).
This looks like a suboptimal example for the speed of ocaml.
Yours, Florian.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Re: Mini ray tracer
2005-05-04 6:24 ` Florian Hars
@ 2005-05-04 7:27 ` Jon Harrop
2005-05-04 11:22 ` Jon Harrop
0 siblings, 1 reply; 6+ messages in thread
From: Jon Harrop @ 2005-05-04 7:27 UTC (permalink / raw)
To: caml-list
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
x86.
> 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
http://www.ffconsultancy.com/products/ocaml_for_scientists
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-05-04 11:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-28 9:37 Mini ray tracer Jon Harrop
2005-05-02 19:48 ` Julian Brown
2005-05-03 22:47 ` [Caml-list] " Jon Harrop
2005-05-04 6:24 ` Florian Hars
2005-05-04 7:27 ` Jon Harrop
2005-05-04 11:22 ` Jon Harrop
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox