caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Eray Ozkural <examachine@gmail.com>
To: caml-list@inria.fr
Subject: min function, why is it so slow?
Date: Thu, 29 Apr 2010 21:34:06 +0300	[thread overview]
Message-ID: <p2o320e992a1004291134i502cec2ap3a6d5c013aa84853@mail.gmail.com> (raw)

Hello there,

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?


In  the following, the first loop is (more than) twice as slow, where
min is defined as

let min a b = if a <= b then a else b


                      for i=1 to  10000000 do
                        x1 := !x1 + (Util.min a1.(i-1) a1.(i));
                      done

                      for i=1 to  10000000 do
                        x1 := !x1 + (if a1.(i-1) <= a1.(i) then a1.(i-1)
                                      else a1.(i))

Time elapsed: 0.189798 (first loop)
Time elapsed: 0.079624 (second loop)

Can someone please explain to me what's going on here? Perhaps there
is inlining, but after inlining, some optimization passes aren't
performed?

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 18:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-29 18:34 Eray Ozkural [this message]
2010-04-29 18:47 ` [Caml-list] " Markus Mottl
2010-04-29 19:12   ` 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=p2o320e992a1004291134i502cec2ap3a6d5c013aa84853@mail.gmail.com \
    --to=examachine@gmail.com \
    --cc=caml-list@inria.fr \
    /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).