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.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 2AD5EBC6C for ; Fri, 18 Jan 2008 02:32:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAACOQj0dIDtyckmdsb2JhbACQFwEBAQEHAgYJChaVFYgA X-IronPort-AV: E=Sophos;i="4.25,213,1199660400"; d="scan'208";a="21452716" Received: from fg-out-1718.google.com ([72.14.220.156]) by mail4-smtp-sop.national.inria.fr with ESMTP; 18 Jan 2008 02:32:00 +0100 Received: by fg-out-1718.google.com with SMTP id l27so1150205fgb.43 for ; Thu, 17 Jan 2008 17:32:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding; bh=VvmwIsZhKBXqEIqzXkpAs/4NKZ36rcuWF0VQyt7DOEg=; b=HMmCMh1S8S+QVjdK3NB/wBmsB1ElteUxBmUVk8YmtYlRuumpVO+dGw3wF0MI2FY6JpKNy8M/e6GdUJPpuomMWcaXTmQJ5dvqeuc6OkJE9a2f/qJhHQdRwc9WnSz+G8WkUlOu4Hgy9nCEUW9aRxOGKsBV+5nU2nTlWodNaNxFnv8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding; b=sYfNodt5xrlZIy+e5Xxn6zFnFTxAYDzBPxIoAA8rk3tTaJ+xXdV17yxwB+QXswTeWJQmH1y7pfJj9flFf+NB8wZ1LGY4enHNkThWlJS01fGFiEJhCg/1sI+4c8RItnryEpifJHNFJKtQxXY1RLQBubBYlWgh6iye4Si/aUcQ4ls= Received: by 10.86.50.8 with SMTP id x8mr2523250fgx.25.1200619920649; Thu, 17 Jan 2008 17:32:00 -0800 (PST) Received: from ?192.168.0.10? ( [82.237.227.151]) by mx.google.com with ESMTPS id l12sm3373707fgb.8.2008.01.17.17.31.58 (version=SSLv3 cipher=RC4-MD5); Thu, 17 Jan 2008 17:31:59 -0800 (PST) Subject: Strange performances From: Benjamin Canou To: OCaml Content-Type: text/plain Date: Fri, 18 Jan 2008 02:32:13 +0100 Message-Id: <1200619933.6383.47.camel@benjamin-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; 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 rec:01 benjamin:01 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