sscanf vs strtok & strrest
#9

Quote:
Originally Posted by Simon
Посмотреть сообщение
pawn Код:
new
    idx;

    for(new i; i < 1000000; i++)
    {
        Integer = strval(strtok(TESTSTRING, idx));
    }
Look at where idx was defined and look at the loop:

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?
That's very true, good job noticing! I'll run a new test to see what the result should be.

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);
}
And here is the very different result:
Код:
[19:33:58] RESULT strtok & strrest: 2266 ticks.
[19:33:58] RESULT sscanf: 465 ticks.
Reply


Messages In This Thread
sscanf vs strtok & strrest - by Lenny the Cup - 08.09.2010, 15:26
Re: sscanf vs strtok & strrest - by playbox12 - 08.09.2010, 15:30
Re: sscanf vs strtok & strrest - by Lenny the Cup - 08.09.2010, 15:33
Re: sscanf vs strtok & strrest - by playbox12 - 08.09.2010, 15:44
Re: sscanf vs strtok & strrest - by Lenny the Cup - 08.09.2010, 16:03
Re: sscanf vs strtok & strrest - by Lenny the Cup - 08.09.2010, 16:26
Re: sscanf vs strtok & strrest - by Simon - 08.09.2010, 23:56
Re: sscanf vs strtok & strrest - by nemesis- - 09.09.2010, 04:23
Re: sscanf vs strtok & strrest - by Lenny the Cup - 09.09.2010, 17:28
Re: sscanf vs strtok & strrest - by Lenny the Cup - 09.09.2010, 17:33

Forum Jump:


Users browsing this thread: 1 Guest(s)