[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: memcpy vs memmove



On Wed, Nov 07, 2012 at 11:11:10AM +0100, Dirk Geschke wrote:
> Hi glibc maintainers,
> 
> I have a performance "problem" which I do not understand. If I allocate
> a memory buffer of 1 GB (aligned to pagesize) and do a memset(), then
> this takes 1.1 seconds. If I copy this buffer to another one using
> memcpy(), it takes about 1.7 seconds. But if I use memmove() or bcopy()
> it takes only 0.7s and 0.5s:
> 
>   memset  took 1.100437 seconds -> 930.54 MB/s
>   memcpy  took 1.366200 seconds -> 749.52 MB/s 
>   bcopy   took 0.703371 seconds -> 1.42 GB/s 
>   memmove took 0.545014 seconds -> 1.83 GB/s 
> 
> I tried to look at the source code, but got lost somewhere. For me it
> looks like they are all using the same code. So I do not understand why
> memcpy() is so slow. Do you have any ideas, hints, pointers, ...?
> 
> >From the C source it looks identically, but there are also some
> assembler codes in the source tree and finally I am not sure which
> code is used for which function.
> 
> I am using wheezy,
> 
>   libc6:amd64    2.13-35      amd64
> 
> but the squeeze version shows the same behaviour. Maybe there is some
> room to optimize memcpy()?
> 

This is something very strange, as memcpy, memmove and bcopy are based
on the same code, but with memcpy and bcopy being the simpler.

Are you really recreating and reinitializing the memory buffer before
each test? The best would be to provide us your test code.

-- 
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net


Reply to: