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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,56525db28240414a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.85.231 with SMTP id k7mr923909paz.38.1342999772280; Sun, 22 Jul 2012 16:29:32 -0700 (PDT) Path: p10ni34667597pbh.1!nntp.google.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!ctu-peer!news.nctu.edu.tw!goblin2!goblin.stu.neva.ru!xlned.com!feeder3.xlned.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Keean Schupke Newsgroups: comp.lang.ada Subject: Re: Efficient Sequential Access to Arrays Date: Sun, 15 Jul 2012 13:03:12 -0700 (PDT) Organization: http://groups.google.com Message-ID: <44f2bfd0-75ed-4b9c-982e-61d5308f9c01@googlegroups.com> References: <01983f1c-f842-4b1f-a180-bcef531dad4c@googlegroups.com> NNTP-Posting-Host: 82.44.19.199 Mime-Version: 1.0 X-Trace: posting.google.com 1342382592 9756 127.0.0.1 (15 Jul 2012 20:03:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 15 Jul 2012 20:03:12 +0000 (UTC) Cc: mailbox@dmitry-kazakov.de In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=82.44.19.199; posting-account=T5Z2vAoAAAB8ExE3yV3f56dVATtEMNcM User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-15T13:03:12-07:00 List-Id: On Sunday, 15 July 2012 20:48:35 UTC+1, Dmitry A. Kazakov wrote: > On Sun, 15 Jul 2012 11:40:08 -0700 (PDT), Keean Schupke wrote: >=20 > > However in order to achieve this performance I needed to rework the = arrays > > as the use of Indexes was too slow. >=20 > You have to measure it in order to know. Write two variants and compare > their performance. Have done, the difference is about 10k simulations per second. >=20 > > An example of this is lets say we are > > accessing element 5 from array A "A(5)" this requires a mu= ltiplication to > > access (base_address + index * record_size). >=20 > It does not, because 5 is constant. Obviously the index is not actually a constant but the result of selecting = a random element in the list. The multiplication is necessary for finding t= his first element, but the operations on relative elements (+/-1, +/-2 etc)= can use addition with a pointer, not so with an index. >=20 > > To access the neighbour A(6) > > also requires a multiplication. Accessing the array sequentially req= uires > > a multiplication per step.=20 >=20 > That depends on loop optimizations. I would expect GCC to optimize access > to array elements per the loop's index. It does not seem to, I'll see if I can post some assembly. >=20 > > So assuming we need this level of performance, what would be the bes= t (and > > most idiomatic Ada) >=20 > Indexing is unlikely to have a significant (>5%) influence on overall > performance. Usually it is other things. It seems to have an significant influence in the benchmarks I have run and = has a particular influence when sequentially accessing elements. >=20 > > way to package this type of usage pattern as an > > abstract datatype? >=20 > Array of aliased elements, to ensure elements independently addressable. Yes, the type itself will need to have aliased elements, but I was assuming= this would be hidden in a package as an ADT, and would expose an indexed-i= terator that has '+' and '-' operations on the iterator (not just a forward= or bidirectional iterator). Cheers, Keean.