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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 46D52BC57 for ; Thu, 29 Apr 2010 20:47:37 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvEBAHtx2UtKfVI2mGdsb2JhbACSSIo/CBUBAQEBAQgJDAcRIq1EgXyFUS6ITgEBAwWFCwQ X-IronPort-AV: E=Sophos;i="4.52,296,1270418400"; d="scan'208";a="61732961" Received: from mail-ww0-f54.google.com ([74.125.82.54]) by mail4-smtp-sop.national.inria.fr with ESMTP; 29 Apr 2010 20:47:37 +0200 Received: by wwb13 with SMTP id 13so651897wwb.27 for ; Thu, 29 Apr 2010 11:47:36 -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; bh=UTvV5ME6JvGBwYy/AMYyXk8yNZuCqiqlobVquRsDymQ=; b=XODXWcqrrbt/Ih7N0Y3/GfKJJ/YfgyH4MZcrmYim8Y6B1Ch1pBMZJ7OdqTpZ5eBiLI k0WbcW/GvKip/Rh9Y5FgDqNs7NQMBR2NvKpiLXBD1Hw9j3bO31if1FJ461sS1MA8ms78 i4+/GMgLdTohxEx/czPOwZuq5Px0jH550xKiQ= 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; b=c+nDQBsaK30ZF01bc4wbMnGFZ2Cv3qwovHeii0UGUH8Da7TqbJw/E6J841SRjSzTAL Yn8ZnGI+iLslBaJx4kv/P4C93tsh4WNngnI8qpC0g7h6a8rjW5Vtwn/RPChAKPE1RmS9 aqauU/D6pDJ8NXzEFQIXoV0UVzm7B9JuliI6s= MIME-Version: 1.0 Received: by 10.216.88.11 with SMTP id z11mr652844wee.116.1272566856505; Thu, 29 Apr 2010 11:47:36 -0700 (PDT) Received: by 10.216.70.206 with HTTP; Thu, 29 Apr 2010 11:47:36 -0700 (PDT) In-Reply-To: References: Date: Thu, 29 Apr 2010 14:47:36 -0400 Message-ID: Subject: Re: [Caml-list] min function, why is it so slow? From: Markus Mottl To: Eray Ozkural Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; 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 integers:01 ocaml:01 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. Your min function is fully polymorphic, which may prevent the OCaml compiler from type specialization, i.e. a generic (= slow) comparison function will be called. E.g. if your array contains integers or floats, this is likely to make a significant difference. Try constraining the type of your min function to the one of the array elements. This will probably make the problem go away. Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com