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-03 12:56:12 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!uni-erlangen.de!news-nue1.dfn.de!news-han1.dfn.de!news-koe1.dfn.de!RRZ.Uni-Koeln.DE!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: What is faster Ada or C? Date: Mon, 3 Dec 2001 20:56:12 +0000 (UTC) Organization: GMUGHDU Message-ID: <9ugotc$rjl$1@a1-hrz.uni-duisburg.de> References: <3c08314d$0$158$9b622d9e@news.freenet.de> <3C0BA624.7A12BFA1@boeing.com> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1007412972 28277 134.91.4.34 (3 Dec 2001 20:56:12 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Mon, 3 Dec 2001 20:56:12 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: archiver1.google.com comp.lang.ada:17358 Date: 2001-12-03T20:56:12+00:00 List-Id: Ted Dennison wrote: : That was "hello world", I believe. I think he actually posted that example at : one point many years back. It sort of cheated, in that it pragma-interface'd to : C for stuff like the IO routines. But then again, there's nothing stopping you : from doing that too if you really want to. :-) : For fun I've tried to check this several times myself; here is one program in C and Ada, without optimization, that shows essentially no difference. Differences have usually vanished when I had asked for optimisation. OTOH, if you follow the assembly output below, they aren't that significant anyway. The programs have been compiled with gcc -S and gcc -S -gnatp respectively. function Silly return Integer is Result: Integer:= 0; begin for K in 1..1000 loop Result:= Result + 1; end loop; return Result; end Silly; int silly() { int result = 0, k; for (k = 1; k <= 1000; k++) { result++; } return result; } Here is side by side output: .file "silly.adb" .file "silly.c" gcc2_compiled.: gcc2_compiled.: ___gnu_compiled_ada: ___gnu_compiled_c: .text .text .align 4 .align 4 .globl __ada_silly .globl _silly __ada_silly: _silly: pushl %ebp pushl %ebp movl %esp,%ebp movl %esp,%ebp subl $8,%esp subl $8,%esp movl $0,-4(%ebp) movl $0,-4(%ebp) movl $1,-8(%ebp) movl $1,-8(%ebp) L2: L2: cmpl $1000,-8(%ebp) cmpl $1000,-8(%ebp) jle L5 jle L5 jmp L3 jmp L3 .align 2,0x90 .align 2,0x90 L5: L5: incl -4(%ebp) incl -4(%ebp) jmp L4 L4: .align 2,0x90 incl -8(%ebp) jmp L3 jmp L2 .align 2,0x90 .align 2,0x90 L6: L3: L4: movl -4(%ebp),%edx incl -8(%ebp) movl %edx,%eax jmp L2 jmp L1 .align 2,0x90 .align 2,0x90 L3: L1: movl -4(%ebp),%edx movl %ebp,%esp movl %edx,%eax popl %ebp jmp L1 ret .align 2,0x90 L1: movl %ebp,%esp popl %ebp ret The optimiser's output is also quite interesting :-) Georg