Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 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