From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 10E67BB9C for ; Wed, 23 Nov 2005 02:55:53 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAN1tqJr023756 for ; Wed, 23 Nov 2005 02:55:52 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA26842 for ; Wed, 23 Nov 2005 02:55:52 +0100 (MET) Received: from ptb-relay04.plus.net (ptb-relay02.plus.net [212.159.14.213]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAN1tpvj023753 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 23 Nov 2005 02:55:52 +0100 Received: from [80.229.56.224] (helo=chetara) by ptb-relay04.plus.net with esmtp (Exim) id 1EejrT-0002tU-8d for caml-list@inria.fr; Wed, 23 Nov 2005 01:55:51 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list Subject: Mandelbrot renderer Date: Wed, 23 Nov 2005 01:50:58 +0000 User-Agent: KMail/1.8.2 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511230150.59163.jon@ffconsultancy.com> X-Miltered: at concorde with ID 4383CC28.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4383CC27.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; renderer:01 ocaml:01 renderer:01 ocaml:01 renders:01 recursive:01 rec:01 frog:98 slower:01 imperative:01 arithmetic:01 opengl:01 caml:02 slightly:02 breaks:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 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