caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yitzhak Mandelbaum <yitzhakm@CS.Princeton.EDU>
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: Thu, 7 Jun 2012 14:54:41 -0400	[thread overview]
Message-ID: <DADAB3EA-8609-43E1-B6AF-10ED7E494318@cs.princeton.edu> (raw)
In-Reply-To: <CE0EBC4C252E4B178BD00227099BA4D4@erratique.ch>

Daniel,

I can't speak definitively, but in my experience, the cost of using a closure had a noticeable performance impact when writing loops as recursive functions. 

Yitzhak

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

> 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
> 
> 
> 
> 
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 

-----------------------------
Yitzhak Mandelbaum




  reply	other threads:[~2012-06-07 18:54 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 [this message]
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
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=DADAB3EA-8609-43E1-B6AF-10ED7E494318@cs.princeton.edu \
    --to=yitzhakm@cs.princeton.edu \
    --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).