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=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 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 39615BC6D for ; Thu, 7 Feb 2008 00:38:23 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAGrTqUfUnw7Vlmdsb2JhbACCN413AQEBAQcEBgcKEQecLA X-IronPort-AV: E=Sophos;i="4.25,314,1199660400"; d="scan'208";a="7019557" Received: from ptb-relay02.plus.net ([212.159.14.213]) by mail2-smtp-roc.national.inria.fr with ESMTP; 07 Feb 2008 00:38:22 +0100 Received: from [80.229.56.224] (helo=beast.local) by ptb-relay02.plus.net with esmtp (Exim) id 1JMtqP-0000uX-KJ for caml-list@yquem.inria.fr; Wed, 06 Feb 2008 23:38:22 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] OCaml image blending performance Date: Wed, 6 Feb 2008 23:34:02 +0000 User-Agent: KMail/1.9.7 References: <854c25eb0802061229o34a6155dncca9d8492cfe6932@mail.gmail.com> In-Reply-To: <854c25eb0802061229o34a6155dncca9d8492cfe6932@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802062334.02485.jon@ffconsultancy.com> X-Plusnet-Relay: bc3106d7d973faac765734c655e96d29 X-Spam: no; 0.00; ocaml:01 incorrectly:01 ocaml:01 inlining:01 metaocaml:01 frog:98 wrote:01 integer:01 ints:01 caml-list:01 computation:01 arithmetic:01 macros:01 caml:02 compiling:02 On Wednesday 06 February 2008 20:29:05 Ilmari Heikkinen wrote: > The C and Caml versions don't produce the same results, but should > have the same amount of computation (don't take my word for it though, > I don't know why the results differ.) You should post working code if you want people to optimize it. I suspect you've incorrectly assumed that OCaml has full-width ints in this case because it does work here on my 64-bit machine. > ./build.sh > > cblend > > real 0m1.466s > user 0m1.456s > sys 0m0.008s > > blend > > real 0m5.463s > user 0m5.456s > sys 0m0.012s > > blend2 > > real 0m3.423s > user 0m3.404s > sys 0m0.012s On 2.2GHz AMD64, I get: $ ./build.sh cblend real 0m6.337s user 0m6.048s sys 0m0.032s blend real 0m14.965s user 0m14.281s sys 0m0.096s blend2 real 0m9.639s user 0m9.333s sys 0m0.056s OCaml is not competitive here for two main reasons: . Full-size integer arithmetic is not very fast in OCaml. . Abstractions often cost performance in OCaml. In this case, most of the speed loss can be regained by simply aggressively inlining everything, which is exactly what you (ab)used C macros for in the C code. If you want to get more interesting then you can look at metaprogramming in OCaml, either by generating OCaml code, using MetaOCaml or JIT compiling using LLVM. You should be able to meet or beat C that way. At the very least, you can write OCaml programs to take the pain away from writing C programs by hand... :-) -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e