Memcpy vs Copy Manually


Introduction
...exactly which one is faster, Memcpy function vs Copy Manually ?!
I faced this problem recently, and I conducted a survey about this issue. The result says Memcpy is much faster than Copy Manually :-) I will take this in my mind in the future and I hope this info will be helpful of you too!
( If you think that this is what everyone knows about, I have to confess that I am ignorant :P )

Experiment
I made these programs, memtest and memwaste . The first one repeats memcpy function for 50000000 times, and the latter one repeats normal copy for the same time, and the operation is totally the same. Which one is exactly faster? ... the normal nerv says that the first one is faster, since it is normal (the latter one is abnormal :P).
These programs measure how long it takes during this what-is-called-useless operations. It will let us know the importance of memcpy function actually.

I run these programs on my machine, FreeBSD 2.2.8 - Pentium II 400MHz, the memory size is 128MB. The result is:

memtest 27.6692 (s)
memwaste 102.868 (s)


hm ... the result says that memtest is about 5 times faster than memwaste. It means we should use memcpy function when we copy array variable, and we should not try to copy the array variable one-by-one.

hm ... maybe I was too ignorant ...


nobu@icnet.ne.jp