caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Manos Renieris <er@cs.brown.edu>
To: Hal Daume III <hdaume@ISI.EDU>
Cc: Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] speed, loops vs. hofs
Date: Tue, 29 Apr 2003 20:45:47 -0400	[thread overview]
Message-ID: <20030430004547.GA14666@cs.brown.edu> (raw)
In-Reply-To: <Pine.GSO.4.21.0304280958590.20131-100000@moussor.isi.edu>

On Mon, Apr 28, 2003 at 10:13:17AM -0700, Hal Daume III wrote:
> One of the primary reasons I use OCaml is because it offers speed,
> together with nice functional stuff, like HOFs.  However, it seems that
> using these together might be impossible.
> 
> I have a module which allows iteration over a particular datatype.  I have
> a method of doing this iteration very quickly using for loops.  In
> particular, I have a function of type:
> 
>   loopPre : hmm -> node -> (node -> int -> bool -> unit) -> unit
> 
[...]
>  Then, at the usage point, I do something like:
> 
>   ...1...
>   loopPre hmm node_j
>     (fun nd len null ->
>       ...2...
>     )
>   ...3...
> 
> I had a sneaking feeling that if I actually stuck the for loops into the
> original code I would get speedups.  However, "...2..." is pretty long, so

If "...2..." is long, then the cost of the function call is going to 
insignificant wrt the cost of running "...2...". In the examples you
wrote, "...2..." is very short, so its cost is comparable to the cost of 
function calls, except ocamlopt is smarter than that and inlines most of them.

There is a chance that after the inlinining there is enough context to
optimize the inlined function bodies further, but I don't know the
innards of the compiler well enough to say if this happens or not.

-- Manos

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      parent reply	other threads:[~2003-04-30  0:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-28 17:13 Hal Daume III
2003-04-29 14:39 ` [Caml-list] " Andrzej M. Ostruszka
2003-04-30  0:45 ` Manos Renieris [this message]

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=20030430004547.GA14666@cs.brown.edu \
    --to=er@cs.brown.edu \
    --cc=caml-list@inria.fr \
    --cc=hdaume@ISI.EDU \
    /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).