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 A2D8BBC57 for ; Thu, 29 Apr 2010 21:12:39 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYCAN522UvRVdrgkGdsb2JhbACQRIIHij8IFQEBAQEJCQwHEQMfqz+BfIVWLohOAQEDBYULBIM3 X-IronPort-AV: E=Sophos;i="4.52,296,1270418400"; d="scan'208";a="49998390" Received: from mail-bw0-f224.google.com ([209.85.218.224]) by mail2-smtp-roc.national.inria.fr with ESMTP; 29 Apr 2010 21:12:39 +0200 Received: by bwz24 with SMTP id 24so15409248bwz.17 for ; Thu, 29 Apr 2010 12:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=ll8TA4PlPKw0UgZ9i0+lTby5/PZ1OEyaPTHw4KxHLbs=; b=bOUQNzvgwNwR0d4U16dW7NZTNZvGyPP6qPzTWJCb4NrRyW1e43WSVRneFHgBOceRTN R/G+Xapd9+hbqeuG7CG4+UY1QFUKe9vU/CN5ipxbydlvfTnGY5XHpE32Jxu0y1GCh1np m8be5cF1Fe7MDnEkY6zUo4/cwauWn+kwOlTJ8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Z0cmep34V/z79DjN6+5Q0NlKefY7naRiAjKm3yASn785eVtkTludZZDyD37uAK08dW ID3+M/RXZR/lXeHFjSy1N5mZe5ujW6f24COlfWQzo1NkW584ci/w4VADmbFn7+ppzKYa 5oMRorxRvvy1fyyAoDwYNR2HwspPp4uDdsLeU= MIME-Version: 1.0 Received: by 10.204.134.151 with SMTP id j23mr6387841bkt.17.1272568359064; Thu, 29 Apr 2010 12:12:39 -0700 (PDT) Received: by 10.204.25.211 with HTTP; Thu, 29 Apr 2010 12:12:39 -0700 (PDT) In-Reply-To: References: Date: Thu, 29 Apr 2010 22:12:39 +0300 Message-ID: Subject: Re: [Caml-list] min function, why is it so slow? From: Eray Ozkural To: Markus Mottl Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; eray:01 ozkural:01 markus:01 mottl:01 markus:01 mottl:01 eray:01 ozkural:01 inlining:01 ocamlopt:01 -inline:01 inlined:01 polymorphism:01 ocaml:01 compiler:01 On Thu, Apr 29, 2010 at 9:47 PM, Markus Mottl wrot= e: > On Thu, Apr 29, 2010 at 14:34, Eray Ozkural wrote: >> Although I turn on inlining in ocamlopt (-inline 10), I think that the >> min function is not quite inlined. Indeed, it's faster if I just >> inline it myself (if a> this way. Which makes me thinking. I suppose a procedure call cost is >> incurred. This doesn't change when I define min for two parameters >> myself in another module. What do you think I am doing wrong? > > This is probably a consequence of too much polymorphism. =A0Your min > function is fully polymorphic, which may prevent the OCaml compiler > from type specialization, i.e. a generic (=3D slow) comparison function > will be called. =A0E.g. if your array contains integers or floats, this > is likely to make a significant difference. =A0Try constraining the type > of your min function to the one of the array elements. =A0This will > probably make the problem go away. Oh, that's a good suggestion, thank you. Let me try it out. Best, --=20 Eray Ozkural, PhD candidate. Comp. Sci. Dept., Bilkent University, Ankara http://groups.yahoo.com/group/ai-philosophy http://myspace.com/arizanesil http://myspace.com/malfunct