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:47)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: [Caml-list] min function, why is it so slow?
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.


Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com