caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Eray Ozkural <examachine@gmail.com>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] min function, why is it so slow?
Date: Thu, 29 Apr 2010 22:12:39 +0300	[thread overview]
Message-ID: <x2h320e992a1004291212kb9b5cfd9rf21f38450f981abf@mail.gmail.com> (raw)
In-Reply-To: <j2kf8560b81004291147qd1b060a2h8c2e10dc5152f591@mail.gmail.com>

On Thu, Apr 29, 2010 at 9:47 PM, Markus Mottl <markus.mottl@gmail.com> wrote:
> On Thu, Apr 29, 2010 at 14:34, Eray Ozkural <examachine@gmail.com> 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<b a then a else b). It's almost twice as fast
>> 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.

Oh, that's a good suggestion, thank you. Let me try it out.

Best,

-- 
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


      reply	other threads:[~2010-04-29 19:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-29 18:34 Eray Ozkural
2010-04-29 18:47 ` [Caml-list] " Markus Mottl
2010-04-29 19:12   ` Eray Ozkural [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x2h320e992a1004291212kb9b5cfd9rf21f38450f981abf@mail.gmail.com \
    --to=examachine@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=markus.mottl@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).