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 AAA02517; Tue, 5 Jun 2001 00:55:16 +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 AAA02410 for ; Tue, 5 Jun 2001 00:55:16 +0200 (MET DST) Received: from smtp4-cm.mail.eni.net (smtp4-cm.mail.eni.net [216.133.226.137]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f54MtED02986 for ; Tue, 5 Jun 2001 00:55:15 +0200 (MET DST) Received: from checkerlap.d6.com (node-d8e9cca2.powerinter.net [216.233.204.162]) by smtp4-cm.mail.eni.net (8.9.3/8.9.3) with ESMTP id PAA06304; Mon, 4 Jun 2001 15:55:10 -0700 Message-Id: <4.3.2.7.2.20010604154828.0298a570@shell16.ba.best.com> X-Sender: def6@shell16.ba.best.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Mon, 04 Jun 2001 15:57:23 -0700 To: Tom _ , William Chesters , caml-list@inria.fr From: Chris Hecker Subject: Re: [Caml-list] OCaml Speed for Block Convolutions In-Reply-To: <20010604221414.49620.qmail@web11906.mail.yahoo.com> References: <15131.59080.327155.47983@beertje.william.bogus> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >maybe it would be better to just make the >straightforward functional implementation fast: > let loop i total = > if i=n then total else > loop (i+1) (total + Array.unsafe_get xs i) > in loop 0 0.0 I was planning on asking about this after I timed it relative to a nonrecursive loop. I noticed a while back that Markus' code for the Language Shootout (for example, http://www.bagley.org/~doug/shootout/bench/matrix/) does tail recursion rather than looping, so I was curious about whether it was superior. However, this doesn't solve all the problems where this crops up: let a = ref 0 in Hashtbl.iter (fun k d -> a := !a + d) my_hash or let hash_to_list h = let l = ref [] in Hashtbl.iter (fun k d -> l := d :: !l) h or whatever. Sometimes these can be handled by fold type functions, but not always (Hashtbl has no fold, for example). Sometimes you need an imperative variable around, and it'd be nice if it was optimal in the easy cases. Since function calls are so cheap these days on branch predicting CPUs, these functional map/iter/fold type things can still be high performance. I haven't done any performance timings yet on these types of operations, though, so a huge grain of salt is attached to this email. Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr