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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.236.216.67 with SMTP id f63mr645699yhp.10.1410445199134; Thu, 11 Sep 2014 07:19:59 -0700 (PDT) X-Received: by 10.140.96.228 with SMTP id k91mr9218qge.23.1410445199113; Thu, 11 Sep 2014 07:19:59 -0700 (PDT) Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!m5no335427qaj.0!news-out.google.com!q8ni8qal.1!nntp.google.com!s7no54760qap.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 11 Sep 2014 07:19:59 -0700 (PDT) In-Reply-To: <0868c42e-ed44-4b36-a929-2bffb338ee34@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=57.79.21.1; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG NNTP-Posting-Host: 57.79.21.1 References: <0868c42e-ed44-4b36-a929-2bffb338ee34@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0b68f842-b99d-40ce-bada-a66e6dbc4e79@googlegroups.com> Subject: Re: Assuming optimization? What is best of these code alternatives? From: gautier_niouzes@hotmail.com Injection-Date: Thu, 11 Sep 2014 14:19:59 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:188965 Date: 2014-09-11T07:19:59-07:00 List-Id: Le jeudi 11 septembre 2014 15:14:39 UTC+2, reinkor a =E9crit=A0: > I am not sure to what extent one may assume the Ada compiler=20 > makes optimization. For example, assume the following two program=20 > code alternatives: [...] > k :=3D i1 + i2; -- store "i1 + i2" in k to avoid recalculation (?) > loop > for i in k .. n loop In any case the value i1 + i2 is the initial value for the loop, so even a = totally non-optimizing compiler will compute the initial loop value once. So in this case: the presence of k will be either, in terms of performance: - neutral (optimized compilation) - slighlty slower (a naive compiler will store i1 + i2 into k, then copy = k into i when initializing the loop) So here k will be only useful if you think it is more readable, especially = if k could appears at many places. _________________________=20 Gautier's Ada programming=20 http://sf.net/users/gdemont/