|
发表于 2007-7-23 22:47:00
|
显示全部楼层
Re: Re: Re: Re:ZeroMemory 和memset的速度谁快?
duzhi5368: Re: Re: Re:ZeroMemory 和memset的速度谁快?
谢谢,学到了. [em5]
给你几段汇编代码看看
vc2003 sp1:
用memset的
int _tmain(int argc, _TCHAR* argv[])
{
00401000 push ebp
00401001 mov ebp,esp
00401003 and esp,0FFFFFFF8h
00401006 mov eax,0C800Ch
0040100B call _chkstk (401090h)
00401010 mov eax,dword ptr [___security_cookie (407030h)]
00401015 xor eax,ebp
00401017 mov dword ptr [esp+0C8008h],eax
0040101E push edi
char szBuff[1024*800];
memset(szBuff, 0, sizeof(szBuff));
0040101F xor eax,eax
00401021 mov ecx,32000h
00401026 lea edi,[esp+8]
0040102A rep stos dword ptr [edi]
return szBuff[1024*800-1];
}
不用memset的:
int _tmain(int argc, _TCHAR* argv[])
{
00401000 push ebp
00401001 mov ebp,esp
00401003 and esp,0FFFFFFF8h
00401006 mov eax,0C800Ch
0040100B call _chkstk (401090h)
00401010 mov eax,dword ptr [___security_cookie (407030h)]
00401015 xor eax,ebp
00401017 mov dword ptr [esp+0C8008h],eax
0040101E push edi
char szBuff[1024*800] = {0};
0040101F xor eax,eax
00401021 mov ecx,31FFFh
00401026 lea edi,[esp+9]
0040102A rep stos dword ptr [edi]
return szBuff[1024*800-1];
}
VC2005 sp1:
不使用memset
00401005 call _chkstk (401820h)
0040100A mov eax,dword ptr [___security_cookie (403000h)]
0040100F xor eax,esp
00401011 mov dword ptr [esp+0C8000h],eax
char szBuff[1024*800] = {0};
00401018 push 0C7FFFh
0040101D lea eax,[esp+5]
00401021 push 0
00401023 push eax
00401024 call memset (40184Ch)
return szBuff[1024*800-1];
使用memset
00401005 call _chkstk (401820h)
0040100A mov eax,dword ptr [___security_cookie (403000h)]
0040100F xor eax,esp
00401011 mov dword ptr [esp+0C8000h],eax
char szBuff[1024*800];
memset(szBuff, 0, sizeof(szBuff));
00401018 push 0C8000h
0040101D lea eax,[esp+4]
00401021 push 0
00401023 push eax
00401024 call memset (40184Ch)
return szBuff[1024*800-1];
}
有没有发现什么?
看你的回答,很无语啊。。。 |
|