From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA17569; Wed, 30 Apr 2003 02:45:51 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA16950 for ; Wed, 30 Apr 2003 02:45:50 +0200 (MET DST) Received: from null.cs.brown.edu (null.cs.brown.edu [128.148.38.190]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h3U0jnH09233 for ; Wed, 30 Apr 2003 02:45:49 +0200 (MET DST) Received: from miette (miette [128.148.38.66]) by null.cs.brown.edu (Postfix) with ESMTP id 607263F64; Tue, 29 Apr 2003 20:45:48 -0400 (EDT) Received: from er by miette with local (Exim 3.36 #1 (Debian)) id 19AfjI-0005TA-00; Tue, 29 Apr 2003 20:45:48 -0400 Date: Tue, 29 Apr 2003 20:45:47 -0400 From: Manos Renieris To: Hal Daume III Cc: Caml Mailing List Subject: Re: [Caml-list] speed, loops vs. hofs Message-ID: <20030430004547.GA14666@cs.brown.edu> Reply-To: Manos Renieris Mail-Followup-To: Hal Daume III , Caml Mailing List References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i X-Spam: no; 0.00; renieris:01 caml-list:01 hofs:01 datatype:01 speedups:01 ocamlopt:01 inlines:01 inlined:01 innards:01 compiler:01 bool:01 ocaml:01 0700,:01 null:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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