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!news.germany.com!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 23 Jan 2009 18:30:22 +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> <97268050-5091-4428-8b48-faf5a14eda25@s9g2000prg.googlegroups.com> <497764a4$0$30231$9b4e6d93@newsspool1.arcor-online.net> <6tu43dFcibgkU1@mid.individual.net> In-Reply-To: <6tu43dFcibgkU1@mid.individual.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4979feaf$0$31870$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 23 Jan 2009 18:30:23 CET NNTP-Posting-Host: 4c60b09f.newsspool3.arcor-online.net X-Trace: DXC=XC3QCL:Gegl]BlmkiiU@BiMcF=Q^Z^V3h4Fo<]lROoRa^YC2XCjHcbi_D5OTc5[VNb;9OJDO8_SKfNSZ1n^B98ij9A31`FHR:>c X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4456 Date: 2009-01-23T18:30:23+01:00 List-Id: Alex R. Mosteo schrieb: > Georg Bauhaus wrote: > >> Maciej Sobczak schrieb: >> >>> The problem here is that the compiler does not inline Update_Element/ >>> Query_Element callbacks. Safety and performance are not in conflict >>> here, it is just a quality of implementation issue. >>> You can have both. >> FWIW, if Iterate/Process is made a generic procedure as >> in the original AI-302, and Increment is made a library >> level procedure, then GNAT confirms, in a sense, >> that there might be a quality of implementation issue: >> >> raw array : 00:00:29.78 >> raw array process : 00:01:06.74 >> raw array generic : 00:00:29.78 > > Do you mean, IIUC, that if 'process' where properly inlined, the timing > would be same for the three instances? That would be nice. The third line seems to indicate the possibility of inlining, provided nothing else gets in the way---in the case of 'Access to procedure; can't say. Complete example with Increment made a library level procedure for all three methods: -- 8<-- procedure Increment (I : in out Integer); pragma Inline(Increment); with Ada.Calendar.Formatting; with Ada.Text_IO; with Increment; procedure Test_P is Iterations: constant := 10_000; 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; generic with procedure Process (Element: in out Integer); procedure Test_0B (Container: in out Int_Array); procedure Test_0B (Container: in out Int_Array) 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 generic : " & Ada.Calendar.Formatting.Image (Stop - Start, True)); end Test_0B; 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); declare procedure Test_G is new Test_0B(Process => Increment); begin Test_G(Z); end; end Test_P; procedure Increment (I : in out Integer) is begin I := I + 1; end Increment;