Mail Archives: djgpp/1996/06/12/20:44:02
Xref: | news2.mv.net comp.os.msdos.djgpp:4892
|
From: | lehmann AT mathematik DOT th-darmstadt DOT de (Alexander Lehmann)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Speed optimization: memcpy() or for loop ??
|
Date: | 12 Jun 1996 16:48:30 GMT
|
Organization: | Technische Hochschule Darmstadt
|
Lines: | 38
|
Message-ID: | <4pmscu$nrt@rs18.hrz.th-darmstadt.de>
|
References: | <4pmlrp$p7u AT crc-news DOT doc DOT ca>
|
NNTP-Posting-Host: | fb0408.mathematik.th-darmstadt.de
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Richard Young (richard DOT young AT crc DOT doc DOT ca) 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.
: With C++ is it better code practice to use b) over a)?
(a) uses the function dj_movedata, which will use the repeat
instruction to copy 4 byte values, which should be pretty fast.
(b) requires a lots of address calculations, unless the compiler is
very smart (I don't think so), but it can be sped up a bit at least
(assuming that x and y are of type foo):
foo *px,*py;
int i;
for(i=n,px=x,py=y; i ; i--) *py++=*px++;
You still don't not get a repeat instruction, but at least you save
the index calculations.
bye, Alexander
--
Alexander Lehmann, | "On the Internet,
alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows
lehmann AT mathematik DOT th-darmstadt DOT de (plain) | you're a dog."
!!CHANGED!! <URL:http://www.mathematik.th-darmstadt.de/~lehmann/>
- Raw text -