comp.lang.ada
 help / color / mirror / Atom feed
From: gautier_niouzes@hotmail.com
Subject: Re: Assuming optimization? What is best of these code alternatives?
Date: Thu, 11 Sep 2014 07:19:59 -0700 (PDT)
Date: 2014-09-11T07:19:59-07:00	[thread overview]
Message-ID: <0b68f842-b99d-40ce-bada-a66e6dbc4e79@googlegroups.com> (raw)
In-Reply-To: <0868c42e-ed44-4b36-a929-2bffb338ee34@googlegroups.com>

Le jeudi 11 septembre 2014 15:14:39 UTC+2, reinkor a écrit :
> I am not sure to what extent one may assume the Ada compiler 
> makes optimization.  For example, assume the following two program 
> code alternatives:
[...]
>     k := 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.
_________________________ 
Gautier's Ada programming 
http://sf.net/users/gdemont/



  parent reply	other threads:[~2014-09-11 14:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <0868c42e-ed44-4b36-a929-2bffb338ee34@googlegroups.com>
2014-09-11 13:34 ` Assuming optimization? What is best of these code alternatives? J-P. Rosen
2014-09-11 14:48   ` Adam Beneschan
2014-09-12  4:32   ` Per Sandberg
2014-09-11 14:19 ` gautier_niouzes [this message]
2014-09-11 14:49   ` Adam Beneschan
2014-09-11 17:30 ` Jeffrey Carter
2014-09-11 18:12 ` Stefan.Lucks
2014-09-12  6:17 ` anon
2014-09-12  8:06   ` reinkor
replies disabled

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