Xref: news2.mv.net comp.os.msdos.djgpp:4968 From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Speed optimization: memcpy() or for loop ?? Date: Thu, 13 Jun 1996 23:13:22 +0100 Organization: The University of York, UK Lines: 33 Message-ID: NNTP-Posting-Host: tower.york.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On 13 Jun 1996, John E. Davis wrote: > Also, if n is a multiple of 2, one could do: > > diff = py - px; > pxmax = px + n; > while (px < pxmax) > { > *(px + diff) = *px; > px++; > *(px + diff) = *px; > px++; > } I think you people are seriously underestimating the power of gcc's optimiser. It is _good_ :-) Tricks like this may occasionally gain a slight speed increase, but in most cases gcc will do them for you if you just write your loop in the simple and obvious way. Making something this complicated can even be counterproductive: it obscures what you are trying to do, so the optimiser is less likely to figure out ways to make it faster. You wouldn't be an ex-Borland user, by any chance? I notice people who have used Borland usually have a hard time trusting the compiler to produce good code without lots of help :-) /* * Shawn Hargreaves. Why is 'phonetic' spelt with a ph? * Check out Allegro and FED on http://www.york.ac.uk/~slh100/ */