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,bb7cc916bd63ab43 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!goblin2!goblin1!goblin.stu.neva.ru!tiscali!newsfeed1.ip.tiscali.net!newsfeed.tiscali.ch!npeer.de.kpn-eurorings.net!npeer-ng1.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 19 Jan 2009 12:25:42 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Performance of element access in Vector References: <0a8baaf0-19f7-40c0-a041-884e93fa7020@w39g2000prb.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <49746336$0$30238$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 19 Jan 2009 12:25:42 CET NNTP-Posting-Host: e34275ff.newsspool1.arcor-online.net X-Trace: DXC=Z>K7^:oI?QXaAeROF2PWMQic==]BZ:af^4Fo<]lROoRQ^YC2XCjHcbY=3CT@19W_A[;9OJDO8_SKVNSZ1n^B98iZAFS[\Zmg8?_ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4406 Date: 2009-01-19T12:25:42+01:00 List-Id: george.priv@gmail.com schrieb: > On Jan 18, 4:42 pm, Maciej Sobczak wrote: >> In a nearby thread I have asked about the performance of >> Update_Element in Vector. >> Each of the tests increments all vectors elements, using several >> element access methods. >> Just to stir the discussion a bit, a straightforward implementation of >> the same test in C++ (with the same base compiler and a single -O2 >> option) runs in 13s with indexed access and in 9.5s with iterators - >> both are based on the use of references, which do not exist in Ada. >> Not very easy to neglect this difference. >> >> All comments are welcome. > Very interesting. > > It seems that compiler is unable to inline. I've added extra test to > see what will be performance with raw array: Starting from your test I have added a fake loop. It is made to simulate the indirection typical of Vector access, calling Increment via 'Access . Indeed, inlining does not seem to happen. Is this a GNAT feature? gnatmake -O1 -W -g -gnato test_p.adb raw array : 00:00:57.47 raw array process : 00:02:13.70 gnatmake -s -O2 -gnatn -gnatN -W -gnatp test_p.adb raw array : 00:00:29.42 raw array process : 00:01:04.18 with Ada.Calendar.Formatting; with Ada.Text_IO; procedure Test_P is Iterations: constant := 10_000; procedure Increment (I : in out Integer) is begin I := I + 1; end Increment; type Int_Array is array(Positive range <>) of Integer; Start : Ada.Calendar.Time; Stop : Ada.Calendar.Time; use type Ada.Calendar.Time; procedure Test_0A (Container: in out Int_Array; Process: not null access procedure (Element: in out Integer)) is begin Start := Ada.Calendar.Clock; for J in 1 .. Iterations loop for Index in Container'Range loop Process(Container(Index)); end loop; end loop; Stop := Ada.Calendar.Clock; Ada.Text_IO.Put_Line ("raw array process : " & Ada.Calendar.Formatting.Image (Stop - Start, True)); end Test_0A; procedure Test_0(Container: in out Int_Array) is begin Start := Ada.Calendar.Clock; for J in 1 .. Iterations loop for I in Container'range loop Container(I) := Container(I) + 1; end loop; end loop; Stop := Ada.Calendar.Clock; Ada.Text_IO.Put_Line ("raw array : " & Ada.Calendar.Formatting.Image (Stop - Start, True)); end Test_0; Z: Int_Array(Positive range 1 .. 1_000_000); begin Test_0(Z); Test_0A(Z, Increment'Access); end Test_P;