English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
min function, why is it so slow?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-04-29 (18:34)
From: Eray Ozkural <examachine@g...>
Subject: min function, why is it so slow?
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));

                      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


Eray Ozkural, PhD candidate.  Comp. Sci. Dept., Bilkent University, Ankara
http://myspace.com/arizanesil http://myspace.com/malfunct