[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2010-04-29 (19:12) |
From: | Eray Ozkural <examachine@g...> |
Subject: | Re: [Caml-list] min function, why is it so slow? |
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