09.09.2010, 17:33
Here are the new versions with the proper reset of idx inside the loop:
And here are the proper results:
Test 1:
Test 2:
pawn Код:
stock Test1()
{
new TickStart,
idx,
szPlayer[MAX_PLAYER_NAME],
iCashAmount,
szEmote[80];
////////////////////////////////////////////////////////////////////////////
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
idx = 0;
iCashAmount = strval(strtok(TESTSTRING, idx));
}
printf("RESULT 1 strtok & strrest: %d ticks.", GetTickCount() - TickStart);
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
sscanf(TESTSTRING, "d", iCashAmount);
}
printf("RESULT 1 sscanf: %d ticks.", GetTickCount() - TickStart);
////////////////////////////////////////////////////////////////////////////
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
idx = 0;
iCashAmount = strval(strtok(TESTSTRING, idx));
format(szPlayer, MAX_PLAYER_NAME, strtok(TESTSTRING, idx));
}
printf("RESULT 2 strtok & strrest: %d ticks.", GetTickCount() - TickStart);
TickStart = GetTickCount();
for(new i; i < 10000; i++)
{
sscanf(TESTSTRING, "du", iCashAmount, szPlayer);
}
printf("RESULT 2 sscanf: %d ticks.", GetTickCount() - TickStart);
////////////////////////////////////////////////////////////////////////////
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
idx = 0;
iCashAmount = strval(strtok(TESTSTRING, idx));
format(szPlayer, MAX_PLAYER_NAME, strtok(TESTSTRING, idx));
format(szEmote, 80, strrest(TESTSTRING, idx));
}
printf("RESULT 3 strtok & strrest: %d ticks.", GetTickCount() - TickStart);
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
sscanf(TESTSTRING, "dus[80]", iCashAmount, szPlayer, szEmote);
}
printf("RESULT 3 sscanf: %d ticks.", GetTickCount() - TickStart);
}
stock Test2()
{
new TickStart,
String[80],
idx;
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
idx = 0;
format(String, 80, strrest(TESTSTRING, idx));
}
printf("RESULT strtok & strrest: %d ticks.", GetTickCount() - TickStart);
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
sscanf(TESTSTRING, "s[80]", String);
}
printf("RESULT sscanf: %d ticks.", GetTickCount() - TickStart);
}
Test 1:
Код:
[19:37:39] RESULT 1 strtok & strrest: 226 ticks. [19:37:39] RESULT 1 sscanf: 47 ticks. [19:37:39] RESULT 2 strtok & strrest: 767 ticks. [19:37:40] RESULT 2 sscanf: 28 ticks. [19:37:40] RESULT 3 strtok & strrest: 861 ticks. [19:37:41] RESULT 3 sscanf: 345 ticks.
Код:
[19:37:41] RESULT strtok & strrest: 106 ticks. [19:37:41] RESULT sscanf: 126 ticks.