comp.lang.ada
 help / color / mirror / Atom feed
From: "SteveD" <nospam_steved94@attbi.com>
Subject: Re: fastest data structure
Date: Wed, 11 Dec 2002 03:23:30 GMT
Date: 2002-12-11T03:23:30+00:00	[thread overview]
Message-ID: <ScyJ9.313000$QZ.46513@sccrnsc02> (raw)
In-Reply-To: at5kmf$3ia$1@news-reader12.wanadoo.fr


"Etienne Baudin" <pfoxNO@SPAMfree.fr> wrote in message
news:at5kmf$3ia$1@news-reader12.wanadoo.fr...
> Hello,
>
> I'd like to know which of these 2 data structures is the fastest to
proceed
> :

Here is my version of a test program to answer the question:

with Ada.Float_Text_Io;
with Ada.Real_Time;
with Ada.Text_IO;

procedure Timing_Test is

   package Float_Text_Io renames Ada.Float_Text_IO;
   package Real_Time renames Ada.Real_Time;
   use type Real_Time.Time_Span;
   package Text_Io renames Ada.Text_IO;

   type My_Type is array (1 .. 100) of Integer;

   type Cell;
   type Ptr is access all Cell;
   type Cell is
      record
         Comp : My_Type;
         Next : Ptr;
      end record;

   procedure Processing (
         Data : My_Type ) is
      Value : Integer;
      pragma Volatile( Value );
   begin
      Value := 42;
   end Processing;

   subtype Testrange is Integer range 1 .. 100_000;

   A : array (Testrange) of My_Type;
   B : array (Testrange) of aliased Cell;
   P : Ptr;

   Start_Time : Real_Time.Time;
   End_Time : Real_Time.Time;
begin
   for I in B'First .. B'Last - 1 loop
      B( I ).Next := B( I + 1 )'access;
   end loop;
   B( B'Last ).Next := null;

   start_Time := Real_Time.Clock;
   for I in A'range loop
      Processing( A(I) );
   end loop;
   End_Time := Real_Time.Clock;
   Text_Io.Put( "Time for array based loop is " );
   Float_Text_Io.Put( Float( Real_Time.To_Duration( end_Time -
Start_TIme ) ), 3, 5, 0 );
   Text_Io.New_Line;

   start_Time := Real_Time.Clock;
   P := B( 1 )'access;
   while (P /= null) loop
      Processing( P.Comp );
      P := P.Next;
   end loop;
   End_Time := Real_Time.Clock;
   Text_Io.Put( "Time for linked list based loop is " );
   Float_Text_Io.Put( Float( Real_Time.To_Duration( end_Time -
Start_TIme ) ), 3, 5, 0 );
   Text_Io.New_Line;

end Timing_Test;

My results are with optimization turned off:

Time for array based loop is   0.00038
Time for linked list based loop is   0.00216

With optimization turned on and checks turned off:

Time for array based loop is   0.00013
Time for linked list based loop is   0.00230

I am using Gnat 3.15p on W2k running on an AMD Athlon 900.

The only way to really answer this question is either through testing (as I
did)
or careful analysis of the code generated by the compiler.

The other thing to note is while the two implementations differ in timing
by an order of magnitude, the overall time is only a couple of milliseconds.

Depending on your application this may or may not matter.

Steve
(The Duck)

>
> Which of the loops is supposed to be the fastest ? Each of the loop should
> run between 1000 and 10_000 times (faces of a 3d object) many (60
expected)
> times per sec, that's why I try to get the best performances.
>
> Thanks
> Etienne Baudin
>
>





  parent reply	other threads:[~2002-12-11  3:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-10 21:01 fastest data structure Etienne Baudin
2002-12-10 22:12 ` Victor Porton
2002-12-11  1:14 ` Jeffrey Carter
2002-12-11  3:23 ` SteveD [this message]
2002-12-11 13:03   ` Marin David Condic
2002-12-11 15:02   ` Etienne Baudin
2002-12-11 15:11     ` Lutz Donnerhacke
2002-12-11 19:04     ` tmoran
2002-12-12  4:22     ` SteveD
2002-12-12 12:40       ` P R Keeble
2002-12-14 16:23       ` Simon Wright
2002-12-17  0:33         ` Randy Brukardt
  -- strict thread matches above, loose matches on Subject: below --
2002-12-10 21:51 Gautier direct_replies_not_read
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox