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 220F9BC48 for ; Wed, 16 Mar 2005 14:41:23 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2GDfL7O022059 for ; Wed, 16 Mar 2005 14:41:22 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j2GDfEHq012696; Wed, 16 Mar 2005 22:41:15 +0900 (JST) Date: Wed, 16 Mar 2005 22:41:08 +0900 (JST) Message-Id: <20050316.224108.35690658.garrigue@math.nagoya-u.ac.jp> To: padiolea@irisa.fr Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] OCaml troll on Slashdot From: Jacques Garrigue In-Reply-To: References: <20050316001819.GB347@first.in-berlin.de> <200503160301.11138.jon@ffconsultancy.com> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 42383781.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 irisa:01 ocaml's:01 hashtbl:01 hashtbl:01 hash:01 hash:01 ocaml:01 recursive:01 inputs:01 writes:01 structures:01 short:01 tail: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: From: Yoann Padioleau > Jon Harrop writes: > > 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. > > I agree, I beleived that too but > I switched from Map to Hashtbl in the "troll" code and Hashtbl sux. > I don't know why. Because the default hash function doesn't work well on complex data-structures, where it has lots of collisions, and results in putting lots of values in the same bucket. It's a bad idea to directly use complex data structures as key anyway, but particularly bad with hash tables. > > In OCaml, non-tail-recursive functions are often faster than their tail > > recursive equivalents for small inputs (e.g. short lists). > > really ? why ? Because tail-recursive versions do some extra work to ensure tail-recursiveness. For instance building a list in reverse order, and converting it back with List.rev at the end. This only pays off for huge lists. Jacques Garrigue