From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 73122BB81 for ; Thu, 15 Dec 2005 13:03:08 +0100 (CET) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.191]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jBFC38P3022272 for ; Thu, 15 Dec 2005 13:03:08 +0100 Received: from [212.227.126.160] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1EmrpD-0004v8-00; Thu, 15 Dec 2005 13:03:07 +0100 Received: from [84.58.142.229] (helo=gate.lan.gerd-stolpmann.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1EmrpD-0000tZ-00; Thu, 15 Dec 2005 13:03:07 +0100 Received: from gps.dynxs.de (localhost [127.0.0.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id CE1C7C097; Thu, 15 Dec 2005 13:03:00 +0100 (CET) Received: from 192.168.1.2 (proxying for 194.127.8.19) (SquirrelMail authenticated user gerd) by gps.dynxs.de with HTTP; Thu, 15 Dec 2005 13:03:00 +0100 (CET) Message-ID: <3943.192.168.1.2.1134648180.squirrel@gps.dynxs.de> In-Reply-To: References: Date: Thu, 15 Dec 2005 13:03:00 +0100 (CET) Subject: Re: [Caml-list] Comments welcomed to progr. style / speed of my first ocaml program "Error correcting LDPC decoder" From: "Gerd Stolpmann" To: "Andries Hekstra" Cc: caml-list@yquem.inria.fr User-Agent: SquirrelMail/1.4.4 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:a6865a839c0178d9aa0ce41878507ea2 X-Miltered: at concorde with ID 43A15B7C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 gerd:01 stolpmann:01 arrays:01 compiler:01 statically:01 omitted:01 compiler:01 inlined:01 gerd:01 stolpmann:01 viktoriastr:01 64293:01 darmstadt:01 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 Andries Hekstra said: > Attached please find the first program I wrote. It has about the same > speed as its C++ counterpart (slightly faster). I welcome comments w.r.= t. > programming style, esp. when it affects the speed of the program. As you are doing a lot of array manipulation, this tip may increase performance significantly: because "float array" is stored with a different layout than all other arrays, the compiler generates a dynamic check for every access when the type of the array elements cannot be statically determined. For example, your function let swapElement i j a =3D let x =3D a.(i) in a.(i) <- a.(j); a.(j) <- x is polymorphic in the element type. If you define instead let swapFloatElement i j (a : float array) =3D let x =3D a.(i) in a.(i) <- a.(j); a.(j) <- x better code is generated because the mentioned check can be omitted by th= e compiler. This applies only if the function is not inlined; swapElement could be small enough (but qsort, for instance, is definitely not). Unfortunately, one cannot define swapNonFloatElement because there is no way to constrain a type that it is not float. So the type system cannot represent this duality float/non-float, and one must fall back to as many definitions as element types are actually used. Gerd ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de ------------------------------------------------------------