From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 34E687ED26 for ; Fri, 8 Jun 2012 01:45:57 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ar4CAPA70U9TkdxEk2dsb2JhbABFtE0iAQEBAQkJCwkUAySCGAEBBAF5BQsLNRE9GgaIGQm5FosdhSBgA4g6kiONHQ X-IronPort-AV: E=Sophos;i="4.75,733,1330902000"; d="scan'208";a="161841534" Received: from smtp-68.nebula.fi ([83.145.220.68]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 08 Jun 2012 01:45:56 +0200 Received: from will.iki.fi (xdsl-83-150-85-71.nebulazone.fi [83.150.85.71]) by smtp-68.nebula.fi (Postfix) with ESMTP id 8CBFB43F04E7; Fri, 8 Jun 2012 02:45:54 +0300 (EEST) Received: from shiny.whome (shiny.whome [192.168.2.50]) by will.iki.fi (Postfix) with ESMTPA id 67FC6A2D; Fri, 8 Jun 2012 02:45:54 +0300 (EEST) Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=windows-1252 From: Ville-Pertti Keinonen In-Reply-To: Date: Fri, 8 Jun 2012 02:45:54 +0300 Cc: caml-list Content-Transfer-Encoding: quoted-printable Message-Id: <8F23E7B0-700A-4666-BD5F-66AA40AB180C@iki.fi> References: To: =?iso-8859-1?Q?Daniel_B=FCnzli?= X-Mailer: Apple Mail (2.1278) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on smtp-68.nebula.fi Subject: Re: [Caml-list] Local functions with arguments or closures ? On Jun 7, 2012, at 8:34 PM, Daniel B=FCnzli wrote: > In the past I remember having indirectly benchmarked two different styles= for writing local functions : =85 > without being able to reach a conclusion. Is there any particular style t= hat is definitively faster ? Does it maybe depend on the number of argument= s and/or on whether loop is recursive or not ?=20 As others have said the difference on modern CPUs shouldn't be too big for = the loop itself. However, if the inner function is a helper function (or a loop that only it= erates a few times) and it's f that is called in a tight loop=85it could be= the case that without closures, f would allocate no memory, in which case = there will be a definite difference. It's still premature optimization unless you're actually running into probl= ems. Lambda lifting should be done by the compiler, not the programmer. It prob= ably wasn't worth it for OCaml because closures are dirt cheap compared to = many other language implementations, and spending any significant time not = allocating memory is quite rare.