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 TAA22074; Sun, 18 Aug 2002 19:19:48 +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 TAA22045 for ; Sun, 18 Aug 2002 19:19:47 +0200 (MET DST) Received: from hickory.cc.columbia.edu (hickory.cc.columbia.edu [128.59.59.202]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7IHGsr15711 for ; Sun, 18 Aug 2002 19:17:13 +0200 (MET DST) Received: from there (tw304h3.cpmc.columbia.edu [156.111.84.180]) by hickory.cc.columbia.edu (8.9.3/8.9.3) with SMTP id NAA10426 for ; Sun, 18 Aug 2002 13:16:52 -0400 (EDT) Message-Id: <200208181716.NAA10426@hickory.cc.columbia.edu> Content-Type: text/plain; charset="iso-8859-1" From: Oleg To: caml-list@inria.fr Subject: [Caml-list] O'Caml vs C++: a little benchmark Date: Sun, 18 Aug 2002 13:17:14 -0400 X-Mailer: KMail [version 1.3.2] MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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. Thanks Oleg [1] http://www.columbia.edu/~ot14/ocaml_vs_cpp/ Sample output while running ./demo_all_root.sh on P3 Xeon 800 MHz w/ 256 Mb RAM: lists 1.323 0.904 (* std::deque *) 16.330 arrays 0.258 <- C++ 16.930 <- ocamlopt rev 0.063 0.009 memory 0.728 1.606 tree 1.338 12.307 ------------------- 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