i am new in C, in the next sample code, in my machine, with n=10000 run in 250 ms. this is "ok".
but with n=100000 the time is 25600, why?
in the asm version, the time is linear. with n=1000000 -> 17 ms.
and with n=10000000 -> 172 ms.
#include <windows.h>
#include <string.h>
#include <stdlib.h>
int szadd(char *dest, char *source, int pos)
{
int temp;
__asm
{
mov eax, -1
mov edi, source
mov esi, dest
add esi, pos
lb1:
add eax, 1
movzx ebx, BYTE PTR[edi +eax]
mov[esi +eax], bl
test bl, bl
jnz lb1
add eax, pos
mov temp, eax
}
return temp;
}
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
long n, t, p;
char *buffer;
char txt[100] = "test ";
buffer = malloc(1024 * 1024 * 64);
p = 0;
n = 10000; //100000 overtime
t = GetTickCount();
while (n > 0)
{
// p=szadd(buffer,txt,p);
strcat(buffer, txt);
n--;
}
t = GetTickCount() - t;
wsprintf(txt, "time: %d\n", t);
MessageBox(0, txt, "", 0);
free(buffer);
return 0;
}