fastest and most effective possible?
#1

Method 1:
Код HTML:
new Iterator: WarPlayers<MAX_PLAYERS>;
foreach (new i : GunGamePlayers) 
{
	// code line, code line ...
       // etc etc etc ...
}
Method 2:
Код HTML:
new WarPlayers[MAX_PLAYERS];
for(new i = 0; i <= GetPlayerPoolSize(); i++)
{
	if(IsPlayerConnected(i) && WarPlayers == 1)
	{
		// code line, code line ...
               // etc etc etc ...
	}
}
I want to choose one method, the most efficient and fastest. Method plan to add on another 20-30 systems.
Reply
#2

Why don't you test them to see which one is faster? Just change the second loop to: for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Why don't you test them to see which one is faster? Just change the second loop to: for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
Why?
Difference?
Код HTML:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
/
Код HTML:
for(new i = 0; i <= GetPlayerPoolSize(); i++)
Reply
#4

Quote:
Originally Posted by Spenker
Посмотреть сообщение
Why?
Difference?
Код HTML:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
/
Код HTML:
for(new i = 0; i <= GetPlayerPoolSize(); i++)
Because the loop won't call the function every iteration, it saves the value in a variable and uses that variable for every iteration.
Reply
#5

Quote:
Originally Posted by Spenker
Посмотреть сообщение
Why?
Difference?
Код HTML:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
/
Код HTML:
for(new i = 0; i <= GetPlayerPoolSize(); i++)
First one calls GetPlayerPoolSize once, and stores its value in j.
Second one calls GetPlayerPoolSize multiple times (Depending on the value it actually outputs).

So yes, the first one is actually faster.

But to answer your main question, iterators (y_iterate/foreach) are much faster.
They only loop through the existing values, while the second one loops N times.
*N = The highest player id in the server.
Reply
#6

Iterator always will be the fastest - just remember to add and remove values from it to not get wonky stuff. You've said that you'll do it for 30 systems. I guess a player can be at most in 1 of those at once (i.e Player in GunGame can't play WarGame at the same time). If you are using latest YSI, you can reduce memory used too:
pawn Код:
enum E_GAME
{
     E_GAME_WAR,
     E_GAME_GUN,
     //etc.
}
new Iterator:GamePlayer<_:E_GAME, MAX_PLAYERS>;

//then
foreach(new playerid:GamePlayer<_:E_GAME_WAR>)
This way you'll only use E_GAME + MAX_PLAYERS cells, not E_GAME * MAX_PLAYERS.
Reply
#7

Thank you all,
300+ players server can be run (for) without lag server?
At the moment only use for, and sometimes I have a little lag. But I do not know if the problem loops. HOST is very performant.
I'll update loops on option 1. [ for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) ]
Reply
#8

Anyone?
Reply
#9

Yes, that for loop is just fine.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)