Execution time bottleneck: How to speed up execution?

Tim McDaniel mcdaniel at adi.com
Wed Feb 13 09:57:59 AEST 1991


racine at yunexus.yorku.ca (Jeff Racine) asks about 

   sum += exp( con * (x[i]-x[j]) * (x[i]-x[j]) );

in a pair of nested loops.

   This part of the algorithm is a bottleneck.

Hallelujah, I just got religion.  This is the *first* optimization
article I remember in comp.lang.c where the author knew that the code
fragment was a bottleneck!  (If it's not a bottleneck, it doesn't
really *matter* what you do; don't put the effort into optimizing if
you're not sure.)

   What are my options? I have heard that assembler
   would be faster. How much faster would assembler be? Would it be worth
   the effort? Are there other alternatives that you can see?

Jeff, if we were telepaths, we wouldn't need netnews.  8-)

Environment: What hardware are you on?  What O. S.?  What C compiler?
What assembler?  What other code is around this fragment?

Data: What's the typical value of N?  Anything special about X[]
(integer or other known GCD, triangular)?  Anyhting special about CON?

Effort: Will this program be run often?  Is N large?  In short, is the
execution time large, and does it matter if it is?  (I presume "yes"
throughout.)  Is the program going to massage the same data on many
runs (i.e. would precomputation help)?

I doubt that assembler would help very much on common systems, though
that's only an ignorant guess.

--
"I'd hang you from my nipples ... but it would shock the children."

Tim McDaniel                 Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Internet: mcdaniel at adi.com                UUCP: {uunet,sharkey}!amara!mcdaniel



More information about the Comp.lang.c mailing list