From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 0C479BC57 for ; Sun, 12 Dec 2010 21:39:48 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq0AAGrCBE1KfVK2kGdsb2JhbACXBYx5CBUBAQIJCQwHEQQlplGMCAEFjHIBBIVKg3uHeg X-IronPort-AV: E=Sophos;i="4.59,333,1288566000"; d="scan'208";a="83625094" Received: from mail-wy0-f182.google.com ([74.125.82.182]) by mail2-smtp-roc.national.inria.fr with ESMTP; 12 Dec 2010 21:39:47 +0100 Received: by wyf19 with SMTP id 19so5448137wyf.27 for ; Sun, 12 Dec 2010 12:39:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:references :in-reply-to:subject:date:organization:message-id:mime-version :content-type:content-transfer-encoding:x-mailer:thread-index :content-language; bh=zQ28sS8A0N4Q/VUos/Vx/8A3JzjHJgK7CkYm3NCbEak=; b=L2H4zPP7D6lnABtve1kfAmwAvnFknUJyPhC4Y8R5b5I3ANlxdSa+BwbUxfX+1oVaD6 5hyyo/bEm1VCdMKshpNqLwgqP1xiOliCAwdhQa3GozQzyoGcI1Oayv1IVYup4iwXymni al9IyWOV7O4mYaTTotwWf1mO/BEzKsTzzCGz4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:references:in-reply-to:subject:date:organization :message-id:mime-version:content-type:content-transfer-encoding :x-mailer:thread-index:content-language; b=fCb/kJ79wkzycMqb+cUnrINBqCBLZLsSRjNLh54lzTRnDYE/ZKi3FElqoPA+D+dDfV 2Ec6rhTbwoyREF+mzMLDhdhwV49waMRIbvUVh4lv4EonUnoOuPXyV+Af9edhyPD9FM5h fpIFCsk5x9qHaK0JAvM9BQndVagi4hzSRHKX4= Received: by 10.216.157.142 with SMTP id o14mr2010wek.37.1292186387220; Sun, 12 Dec 2010 12:39:47 -0800 (PST) Received: from WinEight ([84.93.149.66]) by mx.google.com with ESMTPS id 7sm2702568wet.0.2010.12.12.12.39.45 (version=SSLv3 cipher=RC4-MD5); Sun, 12 Dec 2010 12:39:46 -0800 (PST) From: Jon Harrop To: "'Brian Hurt'" Cc: References: <036001cb9a0c$725acef0$57106cd0$@com> In-Reply-To: Subject: RE: Value types (Was: [Caml-list] ocamlopt LLVM support) Date: Sun, 12 Dec 2010 20:39:34 -0000 Organization: Flying Frog Consultancy Message-ID: <03a201cb9a3c$b1754900$145fdb00$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcuaNljddlM0Pj/LSl+GGep5jGlnZQAA84kg Content-Language: en-gb X-Spam: no; 0.00; ocamlopt:01 ocaml:01 c-like:01 ocaml:01 cheers:01 captain:98 0.82:98 edwin:98 wrote:01 wrote:01 rec:01 rec:01 compiles:01 caml-list:01 arithmetic:01 Brian Hurt wrote: > On Sun, 12 Dec 2010, Jon Harrop wrote: > > let rec collatzLen(c, n) : int = > > if n = 1L then c else > > collatzLen (c+1, if Int64.rem n 2L = 0L then Int64.div n 2L else > > Int64.add (Int64.mul 3L n) 1L);; > > > > let rec loop(i, (nlen, n)) = > > if i = 1L then n else > > let ilen = collatzLen(1, i) in > > let nlen, n = if ilen > nlen then ilen, i else nlen, n in > > loop (Int64.sub i 1L, (nlen, n));; > > Congratulations, Jon, you win today's Captain Obvious award. Using > Int64's, which are forced to be boxed, really slows things down. Apparently boxing isn't the issue here, as I had assumed. On 32-bit, OCaml compiles each arithmetic operation on the int64s to a C function call. > Also, uncurrying all your arguments also slows things down. I see <3% performance improvement from currying everything. > Running your > original code on my 64-bit laptop, it took 6.35s to run the 1M example. > The following alternate code only took 0.82s, for a speed up of almost > 7.75x. According to Edwin, you should be able to get C-like performance by running the OCaml in 64-bit and replacing the div and mod operations with shifts and logical ANDs. > Scaling your timings by a similar amount gives Ocaml a running > speed of 3.14s in your set up, or competitive with F#. I'd be wary of scaling timings by measurements made across different architectures. OCaml seems to be doing completely different things on x86 and x64 here. Cheers, Jon.