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=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!news.stack.nl!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Assuming optimization? What is best of these code alternatives? Date: Thu, 11 Sep 2014 10:30:40 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <0868c42e-ed44-4b36-a929-2bffb338ee34@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 11 Sep 2014 17:30:42 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="5b4eadb0ecf28f7f740a0e18f3715b8f"; logging-data="17016"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7DRMFryzZp9XIapSaFtUjQuZabF4c5IE=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 In-Reply-To: <0868c42e-ed44-4b36-a929-2bffb338ee34@googlegroups.com> Cancel-Lock: sha1:Lx+MY540QEnEYRff60HzhqzXcxs= Xref: number.nntp.dca.giganews.com comp.lang.ada:188973 Date: 2014-09-11T10:30:40-07:00 List-Id: On 09/11/2014 06:14 AM, reinkor wrote: > > What is the "best" alternative? Alternative 2 > is shortest (and probably easier to read), but > could it give slower code that for Alternative 1 ? The question, as always, is what are your timing requirements, and does the clearest version meet them? If so, then there's no need to waste effort worrying about "efficiency". The optimization algorithm is Write the clearest code loop Measure the result exit when measurement meets the requirements Determine what's using the most time, and improve it, keeping it as clear as possible end loop; Other than GNAT with -O0, I'm not aware of any compiler that does no optimization. 25 years ago an Ada-83 compiler produced smaller and faster code than assembler optimized by a team of experts, and optimizers have surely improved since then. So it's folly to think a human can do better than the compiler without some evidence to the contrary. -- Jeff Carter "Clear? Why, a 4-yr-old child could understand this report. Run out and find me a 4-yr-old child. I can't make head or tail out of it." Duck Soup 94