From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Performance of element access in Vector
Date: Mon, 19 Jan 2009 12:25:42 +0100
Date: 2009-01-19T12:25:42+01:00 [thread overview]
Message-ID: <49746336$0$30238$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <c8a97381-667c-4fda-8a1b-b4035f4281b8@o40g2000yqb.googlegroups.com>
george.priv@gmail.com schrieb:
> On Jan 18, 4:42 pm, Maciej Sobczak <see.my.homep...@gmail.com> 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;
next prev parent reply other threads:[~2009-01-19 11:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-18 21:42 Performance of element access in Vector Maciej Sobczak
2009-01-19 0:03 ` george.priv
2009-01-19 3:23 ` george.priv
2009-01-19 11:25 ` Georg Bauhaus [this message]
2009-01-19 16:32 ` (see below)
2009-01-20 2:17 ` Randy Brukardt
2009-01-20 8:03 ` Maciej Sobczak
2009-01-20 8:26 ` Dmitry A. Kazakov
2009-01-20 22:07 ` george.priv
2009-01-21 8:52 ` Maciej Sobczak
2009-01-21 19:25 ` george.priv
2009-01-22 10:01 ` Georg Bauhaus
2009-01-22 12:43 ` Maciej Sobczak
2009-01-22 13:52 ` george.priv
2009-01-21 8:59 ` Dmitry A. Kazakov
2009-01-21 9:19 ` Maciej Sobczak
2009-01-21 10:19 ` Dmitry A. Kazakov
2009-01-21 13:14 ` Maciej Sobczak
2009-01-21 19:00 ` Dmitry A. Kazakov
2009-01-21 13:22 ` Georg Bauhaus
2009-01-23 14:56 ` Alex R. Mosteo
2009-01-20 23:01 ` Randy Brukardt
2009-01-21 9:15 ` Maciej Sobczak
2009-01-21 18:08 ` Georg Bauhaus
2009-01-23 14:55 ` Alex R. Mosteo
2009-01-23 17:30 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox