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-Thread: 103376,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Attributes: gid103376,gid115aec,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!blackbush.cw.net!cw.net!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail Date: Sun, 13 Mar 2005 11:31:10 +0100 From: Georg Bauhaus User-Agent: Debian Thunderbird 1.0 (X11/20050116) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada,comp.realtime Subject: Re: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada)) References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <112rs0bdr2aftdf@corp.supernews.com> <1inxxr988rxgg$.1w9dedak41k89.dlg@40tude.net> <112s1r0rf0o8nca@corp.supernews.com> <112sonip5v4dca6@corp.supernews.com> <112t3de6fu04f38@corp.supernews.com> <1110396477.596174.285520@o13g2000cwo.googlegroups.com> <112vb2t8eonuhed@corp.supernews.com> <1110422108.925127.54110@o13g2000cwo.googlegroups.com> <11329cb96h2p19f@corp.supernews.com> <113394jjvppao64@corp.supernews.com> <1133s3qnmqmbjfb@corp.supernews.com> <4232a9f7$0$26552$9b4e6d93@newsread4.arcor-online.net> <11369p5jrcc6835@corp.supernews.com> <1137falp86qhk89@corp.supernews.com> In-Reply-To: <1137falp86qhk89@corp.supernews.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <42341634$0$1115$9b4e6d93@newsread2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 13 Mar 2005 11:30:12 MET NNTP-Posting-Host: 47033680.newsread2.arcor-online.net X-Trace: DXC=iZ>GV3A0nl:OjE[7VlJ2<0Q5U85hF6f;4jW\KbG]kaM8]kI_X=5Kea6mm_ZVENAW><8JM^O\[iId3c`=i_SY2=m2 X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:9303 comp.realtime:1415 Date: 2005-03-13T11:30:12+01:00 List-Id: CTips wrote: [a C program for measureing p[i] in Ada] Ada program below. It isn't really much longer than the C program as some seem to have expected. > This is not intended to be a real program; it is meant to illustrate how > much slower Ada can get than C. Try and write it as specified and > measure the resulting performance. Done. Performance: either a 10%--50% slowdown, or exactly the same speed. The "Ada" program below has values for N and N2 so that I am at least seing some repeatable figures, but I have tried other values as well. (The L2 processor cache is 256k bytes in size). The C program used for comparison has the exact same values. As you suggested, I have not tried to write an Ada program really, but instead to write the same program using Ada for writing C. The result is twofold: 1) The execution speed of Ada is either much less, 0.92 vs 1.36, or 2) The execution speed is the same, 0.92 vs 0.92. For reasons of explanation, (2) is achieved when you remove a null pointer check that Ada requires for pointer p when doing pointer arithmentic, that is when computing p[1]. The pointer arithmetic function "+" from Interfaces.C.Pointers has been modified so that it omits the null test. But DON'T DO THIS when writing Ada programs, you are messing with Ada's meaning! Ada programs don't do arithmetic on null pointers!) function "+" (Left : Pointer; Right : ptrdiff_t) return Pointer is begin --C if Left = null then --C raise Pointer_Error; --C end if; return To_Pointer (To_Addr (Left) + To_Addr (Elmt_Size * Right)); end "+"; With this change the "Ada" program is exactly as fast as the C program. I hear the opportunist say that you have to modify the Ada library in order to get fast programs... Oh well, so much for rationality in language comparisons ... gcc -O2 -ansi -pedantic (C) gnatmake -O2 -gnatp -gnatN (Ada) GCC 4.0.0 20050215, 2xPIII 800MHz 256k, 1G, load low, no jobs. $ while true ; do ./a.out ; done # done many times with Perm_Arrays; procedure c is use Perm_Arrays; p, q: Int_Array(0 .. N); x: Ptr_Array(0 .. N2); begin setup_array(x, p, q); for i in 1 .. 30_000 loop do_array(x); end loop; end c; with Interfaces.C.Pointers; package Perm_Arrays is use Interfaces; N: constant := 3000; N2: constant := 6000; type Int_Array is array (Natural range <>) of aliased Integer; type Int_Ptr is access all Integer; package Int_Arrays is new C.Pointers(Natural, Integer, Int_Array, -1); type Ptr_Array is array (Natural range <>) of Int_Arrays.Pointer; procedure do_array(x: in Ptr_Array); procedure setup_array(x: out Ptr_Array; p, q: in out Int_Array); end Perm_Arrays; package body Perm_Arrays is use Int_Arrays; procedure do_array(x: in Ptr_Array) is p: Pointer; begin for i in x'range loop p := x(i); increment(p); p.all := i; end loop; end do_array; procedure setup_array(x: out Ptr_Array; p, q: in out Int_Array) is begin for i in p'range loop x(i) := p(i)'unchecked_access; x(i + N) := q(i)'unchecked_access; end loop; end setup_array; end Perm_Arrays; -- Georg