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 6642D7ED27 for ; Sun, 17 Jun 2012 01:14:58 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AukIABcT3U/U4w8EY2dsb2JhbABFtVQYFwgMBxQpghgBAQQBMgFGBQsLISUPAQQoIROHfAEJCa1NH4oGkXMDmmWNHg X-IronPort-AV: E=Sophos;i="4.75,784,1330902000"; d="scan'208";a="163205092" Received: from mout.web.de ([212.227.15.4]) by mail1-smtp-roc.national.inria.fr with ESMTP; 17 Jun 2012 01:14:50 +0200 Received: from frosties.localnet ([95.208.118.96]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0LvS9z-1RyY9b2r8l-0107sD; Sun, 17 Jun 2012 01:14:48 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.77) (envelope-from ) id 1Sg2Ce-00038T-37; Sun, 17 Jun 2012 01:14:48 +0200 From: Goswin von Brederlow To: Daniel Buenzli Cc: caml-list In-Reply-To: ("Daniel Buenzli"'s message of "Thu, 7 Jun 2012 19:34:49 +0200") References: User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) Date: Sun, 17 Jun 2012 01:14:48 +0200 Message-ID: <87vciqj1cn.fsf@frosties.localnet> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Provags-ID: V02:K0:CoduTM61hmlGNkGFxm5zj2EL2x8n8Ed8sT7doIpKutk A44RdhFwdC/S2/qEH5hRet4F9Oamn/54nF5idLJ5P0U1pLe2i5 wEtSg5SoOuGbX5kOiK9DFDsMpg1A+quSHUO5TOOeO4cf4BV8BL P369XAizY/yeMKz566qd8Mtw8Wf/CRlbjKcRD9ZF8w9tRZC4K2 2JnwQDHJZHiGkUZF2uNwQ== Subject: Re: [Caml-list] Local functions with arguments or closures ? Daniel Bünzli writes: > Hello, > > In the past I remember having indirectly benchmarked two different styles for writing local functions : > > let f x = > let v = ... in > let rec loop x v = ... in > loop x v > > or > > let f x = > let v = ... in > let rec loop () = ... (* uses v and x *) in > loop () > > without being able to reach a conclusion. Is there any particular style that is definitively faster ? Does it maybe depend on the number of arguments and/or on whether loop is recursive or not ? > > This question keeps coming back in my mind when I write local functions... I'm sure someone with some knowledge of the compiler's internals can provide a more reasonable answer than benchmarks. > > Best, > > Daniel Closure arguments prevent what little optimization there is in ocaml. So better avoid them where time counts. But your example doesn't have any closure arguments. MfG Goswin