Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] O'Caml vs C++: a little benchmark
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: malc <malc@p...>
Subject: Re: [Caml-list] O'Caml vs C++: a little benchmark
On Sun, 18 Aug 2002, Oleg wrote:

> Hi
> 
> I wrote a few simple benchmarks [1] assessing binaries generated by "ocamlopt 
> -unsafe -noassert" vs binaries generated by "g++-3.2 -O2 -fomit-frame-pointer 
> -pedantic" on P3 Xeon, and the results were quite surprising to me.
> 
> Firstly, I expected iteration over O'Caml lists and integer arrays to be as 
> fast as iteration over std::list and std::vector<int>, respectively. Instead, 
> the benchmark gave me a speed difference of about 10x and 100x in favor of 
> C++ for lists and arrays, respectively.
> 
> Secondly, a little benchmark comparing mutable binary trees of 64 bit floats 
> also showed g++-3.2 to be about an order of magnitude faster.
> 
> What was even more surprising was that O'Caml turned out to be about 10 times 
> faster than C++ for reversing lines in a file. I did not use explicit buffers 
> of any kind in either version, and in C++ program, I used "getline", reading 
> into std::string which should provide about the same level of abstraction and 
> overflow protection as O'Caml string.
> 
> I'm curious as to where these huge differences for these small programs come 
> from.

Oh btw:
[ocaml_vs_cpp]$ g++-3.2 -fomit-frame-pointer -Os list_cpp.cpp -o list_cpp
[ocaml_vs_cpp]$ time ./list_cpp 10000 10000

real    0m1.145s
user    0m1.150s
sys     0m0.000s
[ocaml_vs_cpp]$ icc -O3 -xi list_cpp.cpp -o list_cpp
list_cpp.cpp
[ocaml_vs_cpp]$ time ./list_cpp 10000 10000

real    0m0.518s
user    0m0.510s
sys     0m0.010s

Its been noted elsewhere that GCC tends to produce better code(at least 
for AMD's) when invoked with -Os instead of -O2 (where -Os is really an
-O2 _plus_ optimize for size). And Intel's compiler (6.0) really shines
here. Draw your own conclusions.

-- 
mailto:malc@pulsesoft.com

-------------------
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