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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D7CE6BC69 for ; Thu, 31 May 2007 11:22:35 +0200 (CEST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.232]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4V9MYq8025931 for ; Thu, 31 May 2007 11:22:35 +0200 Received: by wr-out-0506.google.com with SMTP id i28so85397wra for ; Thu, 31 May 2007 02:22:34 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=A+qqOxxN9zU/xW20+XMuyu1y2LnBXq5a8uK589gYPvEj8ZHy/koKTV0Ej7Tis6ceXh9P78sizRP6auXATsbK7+JY+vOKzUSOTHJ6wx1BPgAV+jIpSw0gZytrXOUcCtELJ9FUMIAAP7lB92fUz1M5CojwVSTy9ABxsGKigJx/UHU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=ea7Qh3JtKz+/ksBJi5gxDiZKTX+cIUlk8sBX2HMcH3Zj+0pOLkks/MCLaQLebc6z+IbVpCVaQzg9OaYqCPFAhWgJDBOT+uPwA6ostmr1XUXF3/afu1IVBV/MawmHZc+75Tl3c1z1unVyU2YA4puEeO0gcHXiho56Iyf/siMneo8= Received: by 10.78.130.6 with SMTP id c6mr256582hud.1180603354034; Thu, 31 May 2007 02:22:34 -0700 (PDT) Received: by 10.78.90.19 with HTTP; Thu, 31 May 2007 02:22:34 -0700 (PDT) Message-ID: <5195a210705310222p6aa8482fr70e7bf2b2b631b72@mail.gmail.com> Date: Thu, 31 May 2007 17:22:34 +0800 From: "Yuanchen Zhu" Sender: yuanchen.zhu@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Comparison of OCaml and MLton for numerics In-Reply-To: <200705311008.16662.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <5195a210705302250u6a9e5adey4ed857480f9e5cd8@mail.gmail.com> <200705310717.01553.jon@ffconsultancy.com> <5195a210705310031n19f035e7sc5d96568e86496ae@mail.gmail.com> <200705311008.16662.jon@ffconsultancy.com> X-Google-Sender-Auth: 579b7c4b5cb67f03 X-Miltered: at discorde with ID 465E93DB.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 inlining:01 img:98 img:98 height:98 caml-list:01 computation:01 width:97 let:03 let:03 zhu:04 overhead:04 comparison:04 performs:06 > > You are doing all this computation in your inner loop unnecessarily: > > let getReflected (img:t) y x yr xr = > let w = width img and h = height img in > if x >= 0 && x < w && y >= 0 && y < h then > img.(y).(x) > else > let x = abs x and y = abs y in > let xx = x/w and x' = x mod w and yy = y/h and y' = y mod h in > let x',xr = if xx mod 2 = 0 then (x',1.0) else (w - 1 - x',xr) in > let y',yr = if yy mod 2 = 0 then (y',1.0) else (h - 1 - y',yr) in > img.(y').(x') *. xr *.yr > > Hoist as much as you can from the inner loop and this program will run much > faster in any language. Yes, I am aware of the inefficiency here. Although because of branch prediction on modern CPUs, the actual running time overhead would not be that big. My point, however, is that MLton and OCaml are being fed the same code, and if OCaml performs specializing and proper inlining, it will get almost twice its current performance.