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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 88863BBBC for ; Wed, 1 Mar 2006 06:45:54 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k215jrL6019527 for ; Wed, 1 Mar 2006 06:45:53 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA24059 for ; Wed, 1 Mar 2006 06:45:53 +0100 (MET) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.193]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k215jqjx019524 for ; Wed, 1 Mar 2006 06:45:52 +0100 Received: by zproxy.gmail.com with SMTP id 13so60564nzn for ; Tue, 28 Feb 2006 21:45:52 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=f1qMFtBXkvmI3h84pjCSnzGrMPSJBWMA1L5Gvs0hREKVF/IowcghVYyarEHYZhaxLDG/F6ezMyi2rBCBBoQ7TKsve7OjgiHgN3uFwMK2K8TkyMTWQQ7n3PW+53uTn+f2Vui/fLdFrIx3kJY0OtayQaPmPT9GA1hDIsKPLliJ9yI= Received: by 10.36.220.25 with SMTP id s25mr2667043nzg; Tue, 28 Feb 2006 21:45:52 -0800 (PST) Received: by 10.36.13.11 with HTTP; Tue, 28 Feb 2006 21:45:51 -0800 (PST) Message-ID: Date: Tue, 28 Feb 2006 21:45:51 -0800 From: "Nathaniel Gray" To: "Alessandro Baretta" Subject: Re: [Caml-list] Question on performance/style issue Cc: Ocaml In-Reply-To: <43FF2BC9.6030503@studio.baretta.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <43FF2BC9.6030503@studio.baretta.com> X-Miltered: at nez-perce with ID 44053511.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44053510.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 baretta:01 baretta:01 computations:01 ocamlopt:01 globl:01 mflr:01 addi:01 stw:01 addis:01 lwz:01 addis:01 lwz:01 stw:01 addi: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=RCVD_BY_IP autolearn=disabled version=3.0.3 On 2/24/06, Alessandro Baretta wrote: > I am very fond of the following "duality" operator. > > let (++) x f =3D f x > > I use to write complex computations legibly: instead of > > h(g(f(x))) > I write > > x ++ f ++ g ++ h > > What is the impact of the this programming style on execution performance= ? Looks bad: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D simpleops.ml =3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D let a x =3D print_string x; x ^ "." let b x =3D x ^ x let c x =3D "frotz" ^ x let (++) x f =3D f x let test_oper _ =3D " Hello!" ++ a ++ b ++ a ++ b ++ c ++ a ++ b ++ c let test_normal _ =3D c (b (a (c (b (a (b (a " Hello!"))))))) let _ =3D test_oper () let _ =3D test_normal () =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D end simpleops.ml =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Compiled on a PPC powerbook with: ocamlopt.opt -S -c simpleops.ml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D from simpleops.s =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D =09.globl=09_camlSimpleops__test_oper_66 =09.text =09.align=092 _camlSimpleops__test_oper_66: =09mflr=09r0 =09addi=09r1, r1, -32 =09stw=09r0, 28(r1) L105: =09addis=09r11, 0, ha16(_camlSimpleops+4) =09lwz=09r4, lo16(_camlSimpleops+4)(r11) =09addis=09r11, 0, ha16(_camlSimpleops) =09lwz=09r5, lo16(_camlSimpleops)(r11) =09stw=09r4, 0(r1) =09addis=09r11, 0, ha16(_camlSimpleops) =09lwz=09r4, lo16(_camlSimpleops)(r11) =09addis=09r11, 0, ha16(_camlSimpleops+4) =09lwz=09r6, lo16(_camlSimpleops+4)(r11) =09lwz=09r27, 0(r4) =09addis=09r11, 0, ha16(_camlSimpleops+8) =09lwz=09r7, lo16(_camlSimpleops+8)(r11) =09addis=09r11, 0, ha16(_camlSimpleops) =09lwz=09r8, lo16(_camlSimpleops)(r11) =09addis=09r11, 0, ha16(_camlSimpleops+4) =09lwz=09r9, lo16(_camlSimpleops+4)(r11) =09addis=09r11, 0, ha16(_camlSimpleops+8) =09lwz=09r10, lo16(_camlSimpleops+8)(r11) =09stw=09r9, 20(r1) =09stw=09r10, 24(r1) =09stw=09r8, 16(r1) =09stw=09r7, 12(r1) =09stw=09r6, 8(r1) =09stw=09r5, 4(r1) =09addis=09r3, 0, ha16(_camlSimpleops__8) =09addi=09r3, r3, lo16(_camlSimpleops__8) =09mtctr=09r27 L106:=09bctrl =09lwz=09r4, 0(r1) =09lwz=09r25, 0(r4) =09mtctr=09r25 L107:=09bctrl =09lwz=09r4, 4(r1) =09lwz=09r23, 0(r4) =09mtctr=09r23 L108:=09bctrl =09lwz=09r4, 8(r1) =09lwz=09r21, 0(r4) =09mtctr=09r21 L109:=09bctrl =09lwz=09r4, 12(r1) =09lwz=09r19, 0(r4) =09mtctr=09r19 L110:=09bctrl =09lwz=09r4, 16(r1) =09lwz=09r17, 0(r4) =09mtctr=09r17 L111:=09bctrl =09lwz=09r4, 20(r1) =09lwz=09r15, 0(r4) =09mtctr=09r15 L112:=09bctrl =09lwz=09r4, 24(r1) =09lwz=09r10, 0(r4) =09mtctr=09r10 =09lwz=09r11, 28(r1) =09addi=09r1, r1, 32 =09mtlr=09r11 =09bctr =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Compare that with =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =09.globl=09_camlSimpleops__test_normal_67 =09.text =09.align=092 _camlSimpleops__test_normal_67: =09mflr=09r0 =09addi=09r1, r1, -16 =09stw=09r0, 12(r1) L113: =09addis=09r3, 0, ha16(_camlSimpleops__7) =09addi=09r3, r3, lo16(_camlSimpleops__7) L114:=09bl=09_camlSimpleops__a_57 =09mr=09r4, r3 L115:=09bl=09_camlPervasives__$5e_135 L116:=09bl=09_camlSimpleops__a_57 =09mr=09r4, r3 L117:=09bl=09_camlPervasives__$5e_135 L118:=09bl=09_camlSimpleops__c_61 L119:=09bl=09_camlSimpleops__a_57 =09mr=09r4, r3 L120:=09bl=09_camlPervasives__$5e_135 =09lwz=09r11, 12(r1) =09addi=09r1, r1, 16 =09mtlr=09r11 =09b=09_camlSimpleops__c_61 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D end simpleops.s =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D So no, it looks like the call to ++ isn't compiled away, at least in this case. I also tried with -inline 99 and it didn't help, but I don't know if that's even a valid value for inline. Cheers, -n8 -- >>>-- Nathaniel Gray -- Caltech Computer Science ------> >>>-- Mojave Project -- http://mojave.cs.caltech.edu -->