From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA07463; Mon, 19 Aug 2002 15:13:27 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA07396 for ; Mon, 19 Aug 2002 15:13:26 +0200 (MET DST) Received: from comtv.ru (comtv.ru [217.10.32.4]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7JDDPT10764 for ; Mon, 19 Aug 2002 15:13:26 +0200 (MET DST) Received: from [10.0.66.9] ([10.0.66.9] verified) by comtv.ru (CommuniGate Pro SMTP 3.5.9) with ESMTP-TLS id 4147152; Mon, 19 Aug 2002 17:13:25 +0400 Date: Mon, 19 Aug 2002 17:12:52 +0400 (MSD) From: malc X-X-Sender: malc@home.oyster.ru To: Oleg cc: caml-list@inria.fr Subject: Re: [Caml-list] O'Caml vs C++: a little benchmark In-Reply-To: <200208181716.NAA10426@hickory.cc.columbia.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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, 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