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: Andrzej M. Ostruszka <ostruszk@o...>
Subject: [Caml-list] Re: speed, loops vs. hofs
On Mon, Apr 28 (2003), Hal Daume III wrote:
[...]
> I find these numbers very disturbing.  First, just looking at the
> discrepency between 3 and 4.  I'd imagine this happens because in (3), the
> "let b = false in if not b..." gets folded down to just "cnt := !cnt + 1".  

<< Disclaimer: This is an answer of a newbie :)) >>

I haven't checked the assembler output but it looks like the
>   let f i b = if not b then cnt := !cnt + 1 in
is not inlined in the 4th version -- a bit surprising that default
inlining level is that conservative.

I've cut&pasted the 3rd and 4th functions into the test.ml:
[amo@order ostruszk]$ ocamlopt test.ml
[amo@order ostruszk]$ ./a.out
Time 3 = 1.050000 sec
Time 4 = 3.090000 sec
[amo@order ostruszk]$ ocamlopt -inline 2 test.ml
[amo@order ostruszk]$ ./a.out
Time 3 = 1.050000 sec
Time 4 = 1.050000 sec

As to the module version: it is impossible to inline unknown function.
Functions passed in arguments are unknown to the compiler -- unless
you've got some "whole program analyser" that checks every use of your
loop function -- so every call will be done via the function pointer.

I hope I haven't messed up anything and this will be of any help to you
:)
						Best regards
-- 
    ____   _  ___
   /  | \_/ |/ _ \		Andrzej Marek Ostruszka
  / _ |     | (_) | Instytut Fizyki, Uniwersytet Jagiellonski (Cracow)
 /_/ L|_|V|_|\___/	(PGP <-- finger ostruszk@order.if.uj.edu.pl)

-------------------
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