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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,229a77b902096176 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-10 19:23:31 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mail From: "SteveD" Newsgroups: comp.lang.ada References: Subject: Re: fastest data structure X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc02 1039577010 12.211.13.75 (Wed, 11 Dec 2002 03:23:30 GMT) NNTP-Posting-Date: Wed, 11 Dec 2002 03:23:30 GMT Organization: AT&T Broadband Date: Wed, 11 Dec 2002 03:23:30 GMT Xref: archiver1.google.com comp.lang.ada:31667 Date: 2002-12-11T03:23:30+00:00 List-Id: "Etienne Baudin" 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 > >