From: Markus Mottl <markus.mottl@gmail.com>
To: Eray Ozkural <examachine@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] min function, why is it so slow?
Date: Thu, 29 Apr 2010 14:47:36 -0400 [thread overview]
Message-ID: <j2kf8560b81004291147qd1b060a2h8c2e10dc5152f591@mail.gmail.com> (raw)
In-Reply-To: <p2o320e992a1004291134i502cec2ap3a6d5c013aa84853@mail.gmail.com>
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.
Regards,
Markus
--
Markus Mottl http://www.ocaml.info markus.mottl@gmail.com
next prev parent reply other threads:[~2010-04-29 18:47 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 ` Markus Mottl [this message]
2010-04-29 19:12 ` [Caml-list] " Eray Ozkural
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=j2kf8560b81004291147qd1b060a2h8c2e10dc5152f591@mail.gmail.com \
--to=markus.mottl@gmail.com \
--cc=caml-list@inria.fr \
--cc=examachine@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