caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ville-Pertti Keinonen <will@iki.fi>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Local functions with arguments or closures ?
Date: Fri, 8 Jun 2012 02:45:54 +0300	[thread overview]
Message-ID: <8F23E7B0-700A-4666-BD5F-66AA40AB180C@iki.fi> (raw)
In-Reply-To: <CE0EBC4C252E4B178BD00227099BA4D4@erratique.ch>


On Jun 7, 2012, at 8:34 PM, Daniel Bünzli wrote:

> In the past I remember having indirectly benchmarked two different styles for writing local functions :
> 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 ? 

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 iterates a few times) and it's f that is called in a tight loop…it 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 problems.

Lambda lifting should be done by the compiler, not the programmer.  It probably 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.


  parent reply	other threads:[~2012-06-07 23:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-07 17:34 Daniel Bünzli
2012-06-07 18:54 ` Yitzhak Mandelbaum
2012-06-07 19:07 ` Gabriel Scherer
2012-06-07 20:09   ` AW: " Gerd Stolpmann
2012-06-07 22:10     ` Alain Coste
2012-06-07 23:45 ` Ville-Pertti Keinonen [this message]
2012-06-16 23:14 ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8F23E7B0-700A-4666-BD5F-66AA40AB180C@iki.fi \
    --to=will@iki.fi \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@erratique.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).