sscanf vs strtok & strrest
#10

Here are the new versions with the proper reset of idx inside the loop:
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);
}
And here are the proper results:
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.
Test 2:
Код:
[19:37:41] RESULT strtok & strrest: 106 ticks.
[19:37:41] RESULT sscanf: 126 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)