Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] speed, loops vs. hofs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-04-30 (00:45)
From: Manos Renieris <er@c...>
Subject: Re: [Caml-list] speed, loops vs. hofs
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 Archives:
Bug reports: FAQ:
Beginner's list: