From: malc <malc@pulsesoft.com>
To: Oleg <oleg_inconnu@myrealbox.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] O'Caml vs C++: a little benchmark
Date: Mon, 19 Aug 2002 17:12:52 +0400 (MSD) [thread overview]
Message-ID: <Pine.LNX.4.44.0208191707490.1584-100000@home.oyster.ru> (raw)
In-Reply-To: <200208181716.NAA10426@hickory.cc.columbia.edu>
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.
You made an unlucky choice of summing floats. So what you measure(at least
in list, array cases) is speed of float boxing.
open Printf;;
let n = int_of_string (Sys.argv.(1));;
let r = int_of_string (Sys.argv.(2));;
type _s = { mutable s : float }
let result =
let s = { s = 0.0 } in
let list = Array.to_list (Array.init n (fun i -> i)) in
let rec f = function [] -> () | x :: xs -> s.s <- s.s +. float x; f xs in
for i = 0 to pred r do
f list
done;
s.s
Is what you would probably came to, after reading:
http://caml.inria.fr/ocaml/numerical.html
I'll try to analyze memory, tree etc, if time permits.
P.S.
lists
1.142
0.510
1.298
(Athlon 1.4G(running at 1G), compiled with -inline 20)
--
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
next prev parent reply other threads:[~2002-08-19 13:13 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-18 17:17 Oleg
2002-08-18 18:00 ` William Chesters
2002-08-18 19:06 ` Oleg
2002-08-18 21:37 ` William Chesters
2002-08-19 13:02 ` Xavier Leroy
2002-08-19 13:58 ` [Caml-list] Inlining across functors (was: O'Caml vs C++: a little benchmark) Thorsten Ohl
2002-08-19 21:16 ` malc
2002-08-19 22:06 ` [Caml-list] Specialization (was: Inlining across functors) Thorsten Ohl
2002-08-20 6:35 ` [Caml-list] " malc
2002-08-20 6:25 ` [Caml-list] Inlining across functors (was: O'Caml vs C++: a little benchmark) malc
2002-08-19 14:39 ` [Caml-list] O'Caml vs C++: a little benchmark Oleg
2002-08-19 15:15 ` William Chesters
2002-08-18 19:16 ` Markus Mottl
2002-08-18 19:58 ` Oleg
2002-08-18 22:59 ` Markus Mottl
2002-08-19 13:12 ` malc [this message]
2002-08-19 13:22 ` malc
2002-08-23 21:05 ` John Max Skaller
2002-08-23 21:35 ` Oleg
2002-08-28 13:47 ` John Max Skaller
2002-08-28 14:34 ` Alain Frisch
2002-08-28 17:23 ` inlining tail-recursive functions (Re: [Caml-list] O'Caml vs C++: a little benchmark) Oleg
2002-08-31 1:13 ` John Max Skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.44.0208191707490.1584-100000@home.oyster.ru \
--to=malc@pulsesoft.com \
--cc=caml-list@inria.fr \
--cc=oleg_inconnu@myrealbox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox