caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Mandelbrot renderer
@ 2005-11-23  1:50 Jon Harrop
  2005-11-23  8:00 ` [Caml-list] " David Baelde
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Harrop @ 2005-11-23  1:50 UTC (permalink / raw)
  To: caml-list


Following Oliver's objections regarding the lack of serious software written 
in OCaml (e.g. web servers), I have written a very serious Mandelbrot 
renderer. The program is 35 lines of OCaml and renders using OpenGL. This 
page breaks it down and describes how it works:

  http://www.ffconsultancy.com/free/fractal

I've written a simple, recursive C++ version as well. It weighs in at 45 lines 
but only 6% more bytes. If you specialise the complex-number arithmetic in 
the OCaml:

  let rec mandelbrot i cx cy zx zy =
    if i = 63 || zx *. zx +. zy *. zy > 4. then i else
      let zx = zx *. zx -. zy *. zy and zy = 2. *. zx *. zy in
      mandelbrot (i+1) cx cy (zx +. cx) (zy +. cy)

then, with only -O3, the C++ is actually significantly slower. The performance 
of the C++ improves considerably with -ffast-math so that it is slightly 
faster. The performance of the C++ can be further improved by using an 
imperative style. This is on both AMD64 and x86.

-- 
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] 5+ messages in thread

end of thread, other threads:[~2005-11-24 14:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-23  1:50 Mandelbrot renderer Jon Harrop
2005-11-23  8:00 ` [Caml-list] " David Baelde
2005-11-23 10:10   ` Yaron Minsky
2005-11-23 14:58     ` Christophe Raffalli
2005-11-24 14:43   ` Chris Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).