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-7-bit
X-Google-Thread: 103376,1d575f572a099528
X-Google-Attributes: gid103376,public
X-Google-ArrivalTime: 2001-12-07 10:14:33 PST
Path:
archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!opentransit.net!wanadoo.fr!not-for-mail
From: Pascal Obry
Newsgroups: comp.lang.ada
Subject: Re: What is faster Ada or C?
Date: 07 Dec 2001 19:12:02 +0100
Organization: Home - http://perso.wanadoo.fr/pascal.obry
Message-ID:
References: <3c08314d$0$158$9b622d9e@news.freenet.de>
<3C0BA624.7A12BFA1@boeing.com>
<3C10C26B.AA451459@nbi.dk>
NNTP-Posting-Host: avelizy-103-1-4-169.abo.wanadoo.fr
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: wanadoo.fr 1007748872 27731 80.11.102.169 (7 Dec 2001 18:14:32 GMT)
X-Complaints-To: abuse@wanadoo.fr
NNTP-Posting-Date: 7 Dec 2001 18:14:32 GMT
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1
Xref: archiver1.google.com comp.lang.ada:17599
Date: 2001-12-07T18:14:32+00:00
List-Id:
Jacob Sparre Andersen writes:
> 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:
>
>
> Compilation...: g++ sqrt_timer.cpp -O3
> Execution time: 1460 ms
> Source code:
You certainly want to add -gnatp to have at least two programs close enough to
compare. Note that I have the following results:
- GCC 2.95.2
> time tsqr
1.61803
real 0m 0.86s
user 0m 0.80s
sys 0m 0.01s
- GNAT 3.x
> time sqrt_timer
X = 1.61803398874989E+00
real 0m 1.38s
user 0m 1.38s
sys 0m 0.01s
- GNAT 5.0
> time sqrt_timer
X = 1.61803398874989E+00
real 0m 1.11s
user 0m 1.10s
sys 0m 0.01s
I'm not an expert here but I think most of the difference between the C++ and
Ada version is in the way Sqrt is implemented. Ada put some constraints on the
Sqrt accuracy.
Anyway here the difference is not as big as what you have reported.
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"