30.05.2011, 02:50
(
Последний раз редактировалось SmallMoke; 30.05.2011 в 04:03.
)
@the_chaoz
Is my personal opinion and style of programmer, I believe that they must respect.
@Y_Less
Hey, i make a test superficial
Foreach is 1,4x then faster ..
But is this a good result for my simple code, I made a few in minutes.
Is my personal opinion and style of programmer, I believe that they must respect.
@Y_Less
Hey, i make a test superficial
pawn Код:
#define MaxSlots (500)
#define IsPlayerConnect(%0) (Player1[%0])
#define LoopPlayers(%0) for(new %0,_%0; %0 != -1; %0 = Player2[_%0],++_%0)
new Player2[(MaxSlots + 1)] = -1;
new Player1[(MaxSlots + 1)] = false;
stock CallOnPlayerConnect()
{
new i = 0;
for ( new x; x < (sizeof Player1 - 1); x++)
{
if(!IsPlayerConnected(x)) continue;
Player2[i] = x;
Player1[x] = 10;
i++;
}
return Player2[i++] = -1;
}
public OnPlayerConnect(playerid)
{
CallOnPlayerConnect();
return true;
}
public OnFilterScriptInit()
{
new TickCount = 0;
CallOnPlayerConnect();
#define MAX_TESTS (99999)
//1 Method
TickCount = GetTickCount();
for(new b; b < MAX_TESTS; b++)
{
for ( new slots = GetMaxPlayers( ), i; i < slots; i++ )
{
if(!IsPlayerConnected(i)) continue;
//code
}
}
printf("[1 METHOD] %d ms",GetTickCount() - TickCount);
//2 Method
TickCount = GetTickCount();
for(new b; b < MAX_TESTS; b++)
{
LoopPlayers(i)
{
//code
}
}
printf("[2 METHOD] %d ms",GetTickCount() - TickCount);
//3 Method
TickCount = GetTickCount();
for(new b; b < MAX_TESTS; b++)
{
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
//code
}
}
}
printf("[3 METHOD] %d ms",GetTickCount() - TickCount);
//4 Method
TickCount = GetTickCount();
for(new b; b < MAX_TESTS; b++)
{
foreach(Player, i)
{
}
}
printf("[4 METHOD] %d ms",GetTickCount() - TickCount);
return true;
}
Код:
#Result [01:02:53] [1 METHOD] 621 ms [01:02:53] [2 METHOD] 10 ms [01:02:55] [3 METHOD] 2406 ms [01:02:55] [4 METHOD] 6 ms
But is this a good result for my simple code, I made a few in minutes.