Browse thread
[Caml-list] O'Caml vs C++: a little benchmark
[
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: | -- (:) |
| From: | William Chesters <williamc@p...> |
| Subject: | [Caml-list] O'Caml vs C++: a little benchmark |
Oleg writes:
> I'm curious as to where these huge differences for these small programs come
> from.
>From a very quick look at your array example, the point is very simply
that in your "abstract" fold_left idiom
Array.fold_left (fun x a -> x +. float a) sum ar
the compiler doesn't inline Array.fold_left, and hence not your
anonymous "fun" either, because it doesn't inline anything between
compilation units. You would see this clearly in the assembler output
if you used ocamlopt -S.
This is an example of the general truth that you can get very good
performance out of ocaml, but only as long as you ensure that your
inner loops are coded in a very down-to-earth style.
Whether this is a problem depends on your point of view. If you think
the aim of good programming is to find beautiful abstract formulations
(including the inner loops) which nevertheless compile to optimal
machine code, it's bad. If you think that languages and programming
idioms should stay more or less isomorphic to the execution model of
the CPU then you won't feel a need for it.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners