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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,56525db28240414a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.227.67 with SMTP id ry3mr7723996pbc.8.1342381963134; Sun, 15 Jul 2012 12:52:43 -0700 (PDT) Path: l9ni11930pbj.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Efficient Sequential Access to Arrays Date: Sun, 15 Jul 2012 12:52:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: <646635a0-ca6e-4f90-bfd7-90e9fd41f989@googlegroups.com> References: <01983f1c-f842-4b1f-a180-bcef531dad4c@googlegroups.com> NNTP-Posting-Host: 69.20.190.126 Mime-Version: 1.0 X-Trace: posting.google.com 1342381963 3381 127.0.0.1 (15 Jul 2012 19:52:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 15 Jul 2012 19:52:43 +0000 (UTC) In-Reply-To: <01983f1c-f842-4b1f-a180-bcef531dad4c@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-15T12:52:42-07:00 List-Id: On Sunday, July 15, 2012 12:40:08 PM UTC-6, Keean Schupke wrote: > The Monte-Carlo simulator I am working on is now performing better in Ada= than in C++ using profile-guided compilation (57k simulations per second f= or Ada 'vs' 56k simulations per second for C++). >=20 > However in order to achieve this performance I needed to rework the array= s as the use of Indexes was too slow. An example of this is lets say we are= accessing element 5 from array A "A(5)" this requires a multipli= cation to access (base_address + index * record_size). To access the neighb= our A(6) also requires a multiplication. Accessing the array sequentially r= equires a multiplication per step.=20 >=20 > Contrast this with C++ where we can return a pointer to the array element= , and we just need to add the record_size to step to the next element. >=20 > So assuming we need this level of performance, what would be the best (an= d most idiomatic Ada) way to package this type of usage pattern as an abstr= act datatype? >=20 >=20 > Cheers, > Keean. Hm; the problem is that such optimizations are highly dependent on assumpti= ons that might not be true in the future. Consider, for example, compiling = targeting the JVM: the arrays are not guaranteed to be continuous with cont= iguous components and therefore such a method would invite incorrect result= /behavior to the program. That said, if I needed to resort to such micro-optimizations I'd throw them= all into a generic-package [if possible] and comment the heck out of the s= ubprogram bodies. {Or if you're using a common pattern you might be able to= explain the pattern in the package-body and then do the implementations --= You might be able to get away with a generic-iterator inside the package b= ody.}