comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Assuming optimization? What is best of these code alternatives?
Date: Thu, 11 Sep 2014 10:30:40 -0700
Date: 2014-09-11T10:30:40-07:00	[thread overview]
Message-ID: <lusm81$gjo$1@dont-email.me> (raw)
In-Reply-To: <0868c42e-ed44-4b36-a929-2bffb338ee34@googlegroups.com>

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


  parent reply	other threads:[~2014-09-11 17:30 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
2014-09-11 14:49   ` Adam Beneschan
2014-09-11 17:30 ` Jeffrey Carter [this message]
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