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-10 01:59:34 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!193.213.112.26!newsfeed1.ulv.nextra.no!nextra.com!news1.oke.nextra.no.POSTED!not-for-mail Sender: ohk@maestro.clustra.com Newsgroups: comp.lang.ada Subject: Re: What is faster Ada or C? References: <3c08314d$0$158$9b622d9e@news.freenet.de> <3C0BA624.7A12BFA1@boeing.com> <3C10C26B.AA451459@nbi.dk> From: Ole-Hjalmar Kristensen Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 194.143.59.98 X-Complaints-To: news-abuse@nextra.no NNTP-Posting-Date: Mon, 10 Dec 2001 10:59:33 MET Organization: Nextra Public Access X-Trace: readme.online.no 1007978373 194.143.59.98 Date: 10 Dec 2001 10:59:33 +0100 Xref: archiver1.google.com comp.lang.ada:17667 Date: 2001-12-10T10:59:33+01:00 List-Id: Jacob Sparre Andersen writes: > 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? It's probably not a good idea to include IO in testts like this. The buffer strategy used by the different IO libraries may give very different results. > > 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/ -- Kabelsalat ist gesund. Ole-Hj. Kristensen