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 VAA23874; Sun, 18 Aug 2002 21:19:29 +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 VAA24031 for ; Sun, 18 Aug 2002 21:19:28 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7IJGcr17544 for ; Sun, 18 Aug 2002 21:16:43 +0200 (MET DST) Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.9.3/8.9.3/Debian 8.9.3-21) id VAA09363; Sun, 18 Aug 2002 21:16:13 +0200 Date: Sun, 18 Aug 2002 21:16:13 +0200 From: Markus Mottl To: Oleg Cc: caml-list@inria.fr Subject: Re: [Caml-list] O'Caml vs C++: a little benchmark Message-ID: <20020818191613.GC8185@fichte.ai.univie.ac.at> Mail-Followup-To: Oleg , caml-list@inria.fr References: <200208181716.NAA10426@hickory.cc.columbia.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200208181716.NAA10426@hickory.cc.columbia.edu> User-Agent: Mutt/1.4i Organization: Austrian Research Institute for Artificial Intelligence Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 18 Aug 2002, Oleg wrote: > 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. My timings differ considerably (AMD Athlon 800 MHz 256 MB RAM; g++-2.96; demo_all.sh instead of demo_all_root.sh): lists 0.680 1.030 2.740 arrays 0.250 3.190 rev 0.200 0.070 memory 0.840 2.120 tree 7.280 8.810 Note, btw., that I have measured user time: real time, which you have chosen is just too unstable on my machine. Maybe this explains some of your extreme measurements. I have also used a different file for reversal (/etc/termcap) and have not run things with your root-script. OCaml never inlines and/or unrolls recursive functions, giving iterative solutions in C++ a significant edge concerning optimizations. The same is true for the array solution, where you are even using higher-order functions with "fold_left". > 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. Not on my machine / with my compiler. Btw., not very fair of you to compare ephemeral and persistent datastructures... ;-) > 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. Because the C++-iostream library just sucks (at least the implementation used by g++). OCaml-I/O as provided by the Pervasives-module is way faster. > I'm curious as to where these huge differences for these small > programs come from. Look at the assembler output for details... ;-) Regards, Markus Mottl -- Markus Mottl markus@oefai.at Austrian Research Institute for Artificial Intelligence http://www.oefai.at/~markus ------------------- 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