int Plus(int a, int b)
{
return a + b;
}
_declspec(naked) int PlusAsm(int a, int b)
{
__asm
{
mov ebx, dword ptr ss:[esp+8]
mov edx, dword ptr ss:[esp+4]
add edx, ebx
mov eax, edx
retn
}
}
int _tmain(int argc, _TCHAR* argv[])
{
for(int nCnt = 0; nCnt < 2; ++nCnt)
{
{
g_Timer.StartFrequency(1);
int nResult = 0;
for(int i = 0; i < 1000000000; ++i)
{
nResult += Plus(1,2);
}
g_Timer.EndFrequency(1);
__int64 n64Time = g_Timer.GetTime(1);
printf( "Normal nResult:%d, Time:%I64d\n\n", nResult, n64Time );
}
{
{
g_Timer.StartFrequency(1);
int nResult = 0;
for(int i = 0; i < 1000000000; ++i)
{
nResult += PlusAsm(1,2);
}
g_Timer.EndFrequency(1);
__int64 n64Time = g_Timer.GetTime(1);
printf( "Assemble nResult:%d, Time:%I64d\n\n", nResult, n64Time );
}
}
}
return 0;
}