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-09 04:27:11 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dewar@gnat.com (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: What is faster Ada or C? Date: 9 Dec 2001 04:27:11 -0800 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0112090427.1a26ecde@posting.google.com> References: <3c08314d$0$158$9b622d9e@news.freenet.de> <3C0BA624.7A12BFA1@boeing.com> <3C10C26B.AA451459@nbi.dk> <3C10F77E.6BDD9A3B@nbi.dk> NNTP-Posting-Host: 205.232.38.14 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1007900831 26894 127.0.0.1 (9 Dec 2001 12:27:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 9 Dec 2001 12:27:11 GMT Xref: archiver1.google.com comp.lang.ada:17635 Date: 2001-12-09T12:27:11+00:00 List-Id: Jacob Sparre Andersen wrote in message news:<3C10F77E.6BDD9A3B@nbi.dk>... > When I look at the corresponding assembler code (gnatgcc > -S/g++ -S) I can see that GNU C++ inlines the square root > function, while GNU Ada doesn't. You seem to be assuming that the function called square root in C++ and the function called square root in Ada are the same function, presumably because their names are similar, and both are usable in your context, but they are not at all the same routine. The Ada routine has additional semantics not present in the C++ routine (e.g. the handling of -0.0 which is required to return -0.0). Is this just a theoretical issue? Not at all. Look at the coding for Sqrt in a-ngelfu.adb: function Sqrt (X : Float_Type'Base) return Float_Type'Base is begin if X < 0.0 then raise Argument_Error; -- Special case Sqrt (0.0) to preserve possible -- minus sign per IEEE elsif X = 0.0 then return X; end if; return Float_Type'Base (Aux.Sqrt (Double (X))); end Sqrt; Those extra tests take significant time. Now one can sit back and say "Ada is a junk language, it insists on testing for errors at runtime, and in giving accurate IEEE results, and I don't need either", but that's not a very reasonable position given that if you like you can easily call the C routine directly, since Ada, unlike other languages, carefully defines the syntax and semantics of calling routines written in other languages :-)