From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9A6E9BC32 for ; Wed, 16 Mar 2005 04:00:09 +0100 (CET) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2G30998016101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 16 Mar 2005 04:00:09 +0100 Received: from [80.229.56.224] (helo=chetara) by ptb-relay03.plus.net with esmtp (Exim) id 1DBOlU-0008k0-NB for caml-list@yquem.inria.fr; Wed, 16 Mar 2005 03:00:08 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] OCaml troll on Slashdot Date: Wed, 16 Mar 2005 03:01:10 +0000 User-Agent: KMail/1.7.1 References: <42363A86.6010309@1969.ws> <172f01077499b3d417604d0ad31f2bdb@cs.unm.edu> <20050316001819.GB347@first.in-berlin.de> In-Reply-To: <20050316001819.GB347@first.in-berlin.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200503160301.11138.jon@ffconsultancy.com> X-Miltered: at nez-perce with ID 4237A139.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 imho:01 associative:01 associative:01 ocaml's:01 hashtbl:01 hash:01 memoizing:01 oliver:01 bandel:01 recursive:01 ocaml:01 recursive:01 inputs:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Just for the record, I'd like to dispell a couple of myths: On Wednesday 16 March 2005 01:05, Yoann Padioleau wrote: > IMHO the reason it was slow is because it used associative list (instead of > Map) for associative access, Although Map is asymptotically faster than List.assoc for lookup (O(ln n) vs O(n)), OCaml's Hashtbl and array-based equivalents are typically several times faster than Map. Also, I think that many people would consider the use of an imperative data structure, such as a hash table, for memoizing to be the remit of functional programming. On Wednesday 16 March 2005 00:18, Oliver Bandel wrote: > which does not really looks tail recursive. > Called more than 2 * 10^6 times... > And many other examples... In OCaml, non-tail-recursive functions are often faster than their tail recursive equivalents for small inputs (e.g. short lists). I expect that the functions you have identified fall into this category, so converting them to tail-recursive form is likely to slow the program down rather than speed it up. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists