sscanf vs strtok & strrest
#5

edit: Didn't see your post ******

I ran a new test to see how big the difference was between the two in three different situations:
1: Just a number (strtok(strval) vs "d")
2: A number and a name (strtok(strval) + strtok vs "du")
3: A number, a user AND the string (strtok(strval) + strtok + strrest vs "dus[24]")

Here is the script, same string as before:
pawn Код:
main()
{
    new TickStart,
        idx,
        szPlayer[MAX_PLAYER_NAME],
        iCashAmount,
        szEmote[80];
    ////////////////////////////////////////////////////////////////////////////
    TickStart = GetTickCount();
    for(new i; i < 100000; i++)
    {
        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++)
    {
        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++)
    {
        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);
}
And here are the results:
Код:
[18:03:41] RESULT 1 strtok & strrest: 68 ticks.
[18:03:41] RESULT 1 sscanf: 47 ticks.
[18:03:41] RESULT 2 strtok & strrest: 141 ticks.
[18:03:41] RESULT 2 sscanf: 28 ticks.
[18:03:41] RESULT 3 strtok & strrest: 382 ticks.
[18:03:42] RESULT 3 sscanf: 417 ticks.
NOTE: INVALID TEST, SEE LATER TESTS
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)