From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,1d575f572a099528 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-07 05:22:16 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.uni2.dk!news.net.uni-c.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: What is faster Ada or C? Date: Fri, 07 Dec 2001 14:21:47 +0100 Organization: Centre for Chaos and Turbulence Studies, Niels Bohr Institute Message-ID: <3C10C26B.AA451459@nbi.dk> References: <3c08314d$0$158$9b622d9e@news.freenet.de> <3C0BA624.7A12BFA1@boeing.com> NNTP-Posting-Host: alf.nbi.dk Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.net.uni-c.dk 1007731307 28974 130.225.212.55 (7 Dec 2001 13:21:47 GMT) X-Complaints-To: usenet@news.net.uni-c.dk NNTP-Posting-Date: Fri, 7 Dec 2001 13:21:47 +0000 (UTC) X-Mailer: Mozilla 4.78 [en] (X11; U; OSF1 V4.0 alpha) X-Accept-Language: fo,da,no,sv,is,de,fr,en Xref: archiver1.google.com comp.lang.ada:17562 Date: 2001-12-07T14:21:47+01:00 List-Id: Jeffrey Carter wrote: > Robert Dewar has stated here on several occasions that he has some > equivalent Ada and C programs that produce identical object code when > compiled with gcc. Yes. Related to that, I have two simple, apparantly equivalent programs written in respectively Ada and C++, where the GNU Ada and C++ compilers find it difficult to produce even roughly equivalent binary code or processing speed. * Why are the two programs below not equivalent? * How can I get the Ada program to run as fast as the C++ program? Ada: Compilation...: gnatmake sqrt_timer -O3 -gnatn Execution time: 3460 ms Source code: with Ada.Numerics.Generic_Elementary_Functions; with Ada.Text_IO; with Interfaces.C; procedure Sqrt_Timer is type Scalar is new Interfaces.C.Double; package Math is new Ada.Numerics.Generic_Elementary_Functions (Scalar); function Sqrt (Item : in Scalar) return Scalar renames Math.Sqrt; pragma Inline (Sqrt); X : Scalar := 2.0; begin -- Sqrt_Timer for i in 1 .. 10_000_000 loop X := Sqrt (1.0 + X); end loop; Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X)); end Sqrt_Timer; C++ === Compilation...: g++ sqrt_timer.cpp -O3 Execution time: 1460 ms Source code: #include #include int main (int argl,char* argv[]) { double x=2.0; for(int i=0;i<10000000;i++){ x=sqrt(1.0+x); }; cout << x << endl; }; Jacob -- SSLUG's julekalender - fra den 1. til den 24. december p�: http://www.sslug.dk/julekalender/