Version française
Home     About     Download     Resources     Contact us    
Browse thread
Mandelbrot renderer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Mandelbrot renderer

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