Xref: news2.mv.net comp.os.msdos.djgpp:5190 From: Joern Sierwald Newsgroups: comp.os.msdos.djgpp Subject: Re: Speed optimization: memcpy() or for loop ?? ** Some actual test results ** Date: Thu, 20 Jun 1996 10:24:17 +0200 Organization: Technische Universitaet Hamburg-harburg Lines: 52 Message-ID: <31C90AB1.72EF@tu-harburg.d400.de> References: <4pmlrp$p7u AT crc-news DOT doc DOT ca> <31C2577D DOT 22FD99BD AT alcyone DOT com> <4q679q$4op AT snlsu1> <4q9k75$bgg AT crc-news DOT doc DOT ca> NNTP-Posting-Host: hp03.rz.tu-harburg.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Richard Young wrote: > > > Richard Young wrote: > > > A question for the optimization experts: > > > For moving data, is it faster to use > > > > > > a) memcpy(x,y,n*sizeof(x[0])) > > > or > > > b) for (i = 0; i < n; i++) x[i] = y[i]; > > > > > > or are they basically the same speed. > > Well, I wrote a test program to test several data move options: > > 1) memcpy() > 2) an index based for loop > 3) a ptr based for loop > > The results are: NO DIFFERENCE. > > On my 120 MHz DEC Pentium executing a data move of 100000 floats 2000 times > took roughly 45 seconds for all options. > > I'm a little surprised that memcpy() wasn't faster. Am I getting an inlined > "C" version instead of an assembly coded library function. > Not surprising. You're measuring the memory speed of your computer. The copy loop is in the 1 Level Cache. In the days of the 80286 (no Cache) a movsw was faster than a loop. Now it doesn't matter. Joern .. .. .. .. .. .. .. .. .. .. .. .. ... .. .. .. .. ..