08.09.2010, 15:26
(
Последний раз редактировалось Lenny the Cup; 14.03.2011 в 10:34.
)
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);
}
[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.
stock Test2()
{
new TickStart,
String[80],
idx;
TickStart = GetTickCount();
for(new i; i < 100000; i++)
{
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);
}
[18:30:21] RESULT strtok & strrest: 120 ticks. [18:30:21] RESULT sscanf: 134 ticks.
stock Test3()
{
new TickStart,
Integer,
idx;
TickStart = GetTickCount();
for(new i; i < 1000000; i++)
{
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);
}
[18:34:04] RESULT strtok & strrest: 663 ticks. [18:34:04] RESULT sscanf: 467 ticks.
new
idx;
for(new i; i < 1000000; i++)
{
Integer = strval(strtok(TESTSTRING, idx));
}
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? |
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.
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);
}
[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.