09.09.2010, 17:28
Quote:
pawn Код:
idx is passed as a reference parameter to strtok, meaning that after your first call to strtok it will search from a different place; whereas on the other hand sscanf is still searching from the beginning. You'd probably find after x or so loops that strtok is not getting the value you're expecting, you should reset idx to 0 after each iteration. Is this a fair test or have I missed something? |
Edit: The difference was staggering!
Here is the new code I've used (Notice i = 0; inside the loop)
pawn Код:
stock Test3()
{
new TickStart,
Integer,
idx;
TickStart = GetTickCount();
for(new i; i < 1000000; i++)
{
idx = 0;
Integer = strval(strtok(TESTSTRING, idx));
}
printf("RESULT strtok & strrest: %d ticks.", GetTickCount() - TickStart);
TickStart = GetTickCount();
for(new i; i < 1000000; i++)
{
sscanf(TESTSTRING, "i", Integer);
}
printf("RESULT sscanf: %d ticks.", GetTickCount() - TickStart);
}
Код:
[19:33:58] RESULT strtok & strrest: 2266 ticks. [19:33:58] RESULT sscanf: 465 ticks.