From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 63CFABC69 for ; Thu, 3 Jan 2008 17:01:57 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAMaVfEdDWxLC/2dsb2JhbACBV6g/ X-IronPort-AV: E=Sophos;i="4.24,240,1196636400"; d="scan'208";a="6250312" Received: from ip67-91-18-194.z18-91-67.customer.algx.net (HELO server1.bertec.net) ([67.91.18.194]) by mail1-smtp-roc.national.inria.fr with ESMTP; 03 Jan 2008 17:01:55 +0100 Received: from kuba.bertec.net (kuba.bertec.net [192.168.2.16]) by server1.bertec.net (Postfix) with ESMTP id 49603CDFBC for ; Thu, 3 Jan 2008 11:01:53 -0500 (EST) From: Kuba Ober To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] [NEWBIE] is there an in-place map? Date: Thu, 3 Jan 2008 11:01:52 -0500 User-Agent: KMail/1.9.6 (enterprise 0.20071123.740460) References: <200801021152.30105.ober.14@osu.edu> <477BCB94.8060208@janestcapital.com> <477BE419.8080400@gmail.com> In-Reply-To: <477BE419.8080400@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801031101.52250.ober.14@osu.edu> X-Spam: no; 0.00; for-loop:01 recursion:01 recursion:01 recursive:01 arrays:01 compiler:01 cheers:01 garbage:01 wrote:01 wrote:01 clearer:01 ints:01 caml-list:01 arithmetic:01 tail:01 On Wednesday 02 January 2008, you wrote: > Brian Hurt wrote: > > The OP did say "in place modification. > > Kuba also said "the output array is given as the argument, not as a > return value." > > > It depends. If you have to use multiple references to make the for-loop > > work, then I've seen tail recursion be faster (and clearer). > > Any example of a faster tail recursion? > > > Also, if > > you recalculate the ending requirement every recursive call, recursion > > can be slower (in the above for loop above, for example, Array.length is > > gaurenteed to be called only once). > > I have no problems precalculating the Array.length value, or recursing > down to 0. > > > Brian > > A little testing results in some data: for arrays of 1024 ints and > simple arithmetic operations, I get a 9% speed increase in using a for > loop over recursion. It seems to be such a basic operation, I was thinking that it must be there. Array.map is fine and dandy, but it is a premature pessimization if used repeatedly unless the compiler would be very smart about it. It's one of the common Java pessimizations too: generating lots of garbage at the same spot in a tight loop. Cheers, Kuba