Re: Optimization by hand.

From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 10/09/04


Date: Fri, 08 Oct 2004 22:38:53 GMT


"Steven T. Hatton" <susudata@setidava.kushan.aa> wrote in message
news:vtmdnaMybrPKZfvcRVn-rA@speakeasy.net...
> Mike Wahler wrote:
>
> >
> > "Steven T. Hatton" <susudata@setidava.kushan.aa> wrote in message
> > news:Q_6dnT3uBccfbPvcRVn-pw@speakeasy.net...
> >> In the following code I have attempted to perform all calculations that
> > are
> >> repeated in the mathematical expression for the rotation being
evaluated.
> >> IOW, I calculate cos(_angle) only once, and put it in a variable.
> >> Perhaps
> >> a compiler is smart enough to do this for me. I don't know. When I get
a
> >> chance I plan on trying to look at the compiler output to determine
what
> > is
> >> happening with gcc.
> >>
> >> I'm wondering what others think about this kind of hand optimization.
> >
> > I think one should give the compiler first crack at it,
> > then only 'hand optimize' if necessary. But even before
> > doing that, I'd first try a different compiler(s).
> >
> > -Mike
> The real question is whether I have removed operations from the object
code,
> and/or replaced them with more efficient operations.

That depends entirely upon the implementation (and upon the
platform where the program is executed). The question cannot
be answered from a language perspective.

> Sure, I can and will
> experiment with this. I know from experience that when I start performing
> multiple nested operations on nodes in a tree the cost can get very high
in
> a hurry. O(log(n)) IIRC.

Yes it can, at the algorithmic level. How various compiler implement
the algorithm can vary widely, resulting in widely differing performance.

> I'm not trying to solve one problem. I'm trying to address an entire
class
> of problems. If there are formal discussions of these issues available in
> articels or books, I am interested to know where.

For discussion of algorithmic solutions, try an algorithms group.
And there are also always the famous Knuth books.

For discussion of the efficiency of implementation of particular
compilers, ask in groups about those compilers.

I can't at the moment think of any particular books or articles
about these issues, but google's always a good place to start. :-)

-Mike



Relevant Pages

  • Re: randon-number generation in kernel
    ... Why not use a good algorithm? ... Read the books. ... There is a kernel random ... but just like the compiler version it requires a good ...
    (microsoft.public.development.device.drivers)
  • Re: Is C99 the final C? (some suggestions)
    ... >> of the reasons why that algorithm is worthless. ... I agree with Paul that this is a very basic and very obvious fact ... kind of mutex to block out one of the threads while the other one ... I don't expect the compiler to do anything with this information. ...
    (comp.lang.c)
  • Re: To Richard Heathfield: enoughs enough
    ... Abandoning Hungarian notation because it is ... So write you're own compiler for a new language, ... >> I don't own any such books. ... Not even Microsoft claims that anymore. ...
    (comp.programming)
  • Re: Challenae question for mathematician
    ... problems relating to permutation groups. ... adjacent books. ... called "bubble sort" - it is a quadratic time algorithm, ... efficient as a sorting method - efficient sorting is O. ...
    (sci.math)
  • Re: Answer needed
    ... and I do acknowledge that there are some programmers like ... >| compiler they are using does what they expected. ... that, in books, in articles, in course material and notes. ... I think the issue of unlearning is much more complicated than you think ...
    (alt.comp.lang.learn.c-cpp)