From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, SPF_SOFTFAIL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 7B2B7BC6C for ; Fri, 18 Jan 2008 03:15:17 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CADeaj0eCNhAB/2dsb2JhbACtZQ X-IronPort-AV: E=Sophos;i="4.25,213,1199660400"; d="scan'208";a="8022522" Received: from kurims.kurims.kyoto-u.ac.jp ([130.54.16.1]) by mail3-smtp-sop.national.inria.fr with ESMTP; 18 Jan 2008 03:15:15 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id m0I2FBEE017240; Fri, 18 Jan 2008 11:15:11 +0900 (JST) Date: Fri, 18 Jan 2008 11:15:03 +0900 (JST) Message-Id: <20080118.111503.185813743.garrigue@math.nagoya-u.ac.jp> To: benjamin.canou@gmail.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Strange performances From: Jacques Garrigue In-Reply-To: <1200619933.6383.47.camel@benjamin-laptop> References: <1200619933.6383.47.camel@benjamin-laptop> X-Mailer: Mew version 4.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; bytecode:01 segfaults:01 bytecode:01 bug:01 failwith:01 endline:01 pred:01 ocamlopt:01 ocamlc:01 ocaml:01 -version:01 toplevel:01 123.:98 123.:98 rec:01 The problem seems to be in list_of_string. If I write: let list_of_string s = let rec list_of_string s i = if i < String.length s then s.[i] :: list_of_string s (succ i) else [] in list_of_string s 0 I get a 10 time increase in speed for bytecode, and 5 times better for native code, as one would expect. Out-of-bounds exceptions are intended as fatal errors, do not try to catch them... By the way, on my machine your version doesn't even work in native code, I only get segfaults. This is allowed behaviour for out-of-bounds access. Jacques Garrigue From: Benjamin Canou > Hi, > > The code following my message is way faster in bytecode than in native > code. Is there a good reason for that or is it a bug ? > Note : It is a (way too, I know) naive implementation of the well known > string suite 1, 11, 21, 1211, 111221, ... > > Benjamin Canou. > > === code === > > let list_of_string s = > let rec list_of_string s i = > try s.[i] :: list_of_string s (succ i) > with _ -> [] > in list_of_string s 0 > > let rec trans = function > | '1' :: '1' :: '1' :: tl -> "31" ^ trans tl > | '1' :: '1' :: tl -> "21" ^ trans tl > | '1' :: tl -> "11" ^ trans tl > | '2' :: '2' :: '2' :: tl -> "32" ^ trans tl > | '2' :: '2' :: tl -> "22" ^ trans tl > | '2' :: tl -> "12" ^ trans tl > | '3' :: '3' :: '3' :: tl -> "33" ^ trans tl > | '3' :: '3' :: tl -> "23" ^ trans tl > | '3' :: tl -> "13" ^ trans tl > | [] -> "" > | _ -> failwith "bad input" > > let rec print n s = > print_endline s ; > if n > 0 then print (pred n) (trans (list_of_string s)) > > let _ = print 30 "1" > > === perfs === > > benjamin@benjamin-laptop:~/Work/Stuff$ ocamlopt 123.ml -o 123 > benjamin@benjamin-laptop:~/Work/Stuff$ time ./123 > [...] > real 0m5.245s > user 0m4.944s > sys 0m0.016s > benjamin@benjamin-laptop:~/Work/Stuff$ ocamlc 123.ml -o 123 > benjamin@benjamin-laptop:~/Work/Stuff$ time ./123 > [...] > real 0m1.097s > user 0m0.840s > sys 0m0.008s > benjamin@benjamin-laptop:~/Work/Stuff$ ocaml -version > The Objective Caml toplevel, version 3.09.2