Execution time bottleneck: How

Steve Summit scs at adam.mit.edu
Sat Feb 23 04:45:16 AEST 1991


In article <492 at tin.crc.ac.uk> dcurtis at crc.ac.uk (Dr. David Curtis) writes:
> Now what follows I'm less sure of. The main aim is to avoid calculating
> array offsets and just increment pointers instead. Can anyone say if 
> that kind of thing produces significant speed-ups?

Schade; this comes up one week too soon.  Here is a sneak preview
of revision 1.24 of the comp.lang.c frequently-asked questions
list, coming soon to a spool directory near you:

100. Are pointers really faster than arrays?  Do function calls really
     slow things down?

A:   The answers to these and many similar questions depend of course on
     the processor and compiler in use.  If you simply must know, you'll
     have to time test programs carefully.  (Often the differences are
     so slight that tens or hundreds of thousands of iterations are
     required even to see them.  Check the compiler's assembly language
     output to see if two purported alternatives aren't compiled
     identically.)

     It is "usually" faster to march through large arrays with pointers
     rather than array subscripts, but for some processors the reverse
     is true.

     Function calls, though obviously incrementally slower than in-line
     code, contribute so much to modularity and code clarity that there
     is rarely good reason to avoid them.

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.lang.c mailing list