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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 43E42BC6C for ; Thu, 7 Feb 2008 15:10:25 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAMqfqkdA6aaxi2dsb2JhbACQMgEBAQgEBAkKEQWWF4VL X-IronPort-AV: E=Sophos;i="4.25,316,1199660400"; d="scan'208";a="22355764" Received: from py-out-1112.google.com ([64.233.166.177]) by mail4-smtp-sop.national.inria.fr with ESMTP; 07 Feb 2008 15:10:24 +0100 Received: by py-out-1112.google.com with SMTP id v53so4020926pyh.33 for ; Thu, 07 Feb 2008 06:10:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=gYePD5YNEFwmGDwrzIZLU2mmvG9V7Q5kGOHJ0yXPJxc=; b=gmqotcu3/XRmG6ey06HolgncjE9uL7uYDEJ9uH2c9+pT0bgUiFL+/Qn8RisOgblr1o8vGWopgmFmb55xE1wMHzH3sScexPrsbUtupRCIat78s72gIDhAY9srqofS3FJh5VeZ0dOoTYpEu+ZJLaXR3PzAvwcxLlKxfJ2f9n3owDk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LxtUo51dkrfqjcaJQ59AEsGF9r9//Bn2MvdTH16ZLStgfnNc1lPm1UClx6Md/lM/mXCkxVZ/6jfUfw1z6uDjRIDHtDe5TT5sc56lldb7axsS3lFB/HMyiBwC5evA6tbnt2uWOR/erePGYQsogMG8XtvjYjMu+HUkbpd8duuZNPg= Received: by 10.35.87.8 with SMTP id p8mr12522146pyl.16.1202393422801; Thu, 07 Feb 2008 06:10:22 -0800 (PST) Received: by 10.35.98.17 with HTTP; Thu, 7 Feb 2008 06:10:22 -0800 (PST) Message-ID: <854c25eb0802070610t1e050875y10de0092f9eb7c4e@mail.gmail.com> Date: Thu, 7 Feb 2008 16:10:22 +0200 From: "Ilmari Heikkinen" To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] OCaml image blending performance In-Reply-To: <854c25eb0802070607t4b2ed641xa3bc19e8384ce23@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <854c25eb0802061229o34a6155dncca9d8492cfe6932@mail.gmail.com> <200802062334.02485.jon@ffconsultancy.com> <854c25eb0802070607t4b2ed641xa3bc19e8384ce23@mail.gmail.com> X-Spam: no; 0.00; ocaml:01 incorrectly:01 ocaml:01 inlining:01 hofs:01 hackery:01 wrote:01 wrote:01 integer:01 inline:01 ints:01 caml-list:01 computation:01 arithmetic:01 macros:01 On Feb 7, 2008 1:34 AM, Jon Harrop wrote: > 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. Actually, it does work here as well, I probably tested earlier with extra blend modes enabled in C. Sorry about the confusion, should've done a more thorough test before posting. > 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. The C macros were more about making the code shorter by emulating HOFs, blend2.ml does inline everything. Coming within 2x of C with no major hackery on this sort of code is impressive though. -- Ilmari Heikkinen