C++内嵌汇编 兼 速度测试

顺便内联汇编写了个strcpy,做个例子并测试了下速度。。

char* strcpy( char* des, const char* src, unsigned __int32 count )
{
if ( des == NULL )
{
return 0;
}

if ( src == NULL )
{
des[ 0 ] = 0;
return des;
}

__asm
{
mov edi, des
mov esi, src
mov ecx, count
dec ecx

__loop:
cmp byte ptr [esi], 0
jz __break
movsb
loop __loop

__break:
mov byte ptr [edi], 0
mov eax, des
}
}

int main()
{
BYTE byType = 2;
char des[ 10 ] = { 0 };
char* src = "masefee";

LARGE_INTEGER iTemp;
LONGLONG llTime1, llTime2;
double dTime;
QueryPerformanceFrequency( &iTemp );
QueryPerformanceCounter( &iTemp );
llTime1 = iTemp.QuadPart;

strcpy( des, src, 8 );

QueryPerformanceCounter( &iTemp );
llTime2 = iTemp.QuadPart;
dTime = ( double )( llTime2 - llTime1 );

printf( "%f/n", dTime );

return 0;
}

输出速度:1210.000000

你可能感兴趣的:(C++)