Quote:
Originally Posted by Lee
I'd appreciate it if someone who isn't lazy would make a comparison of get_players() and looping over each slot, but I'll understand if I get ignored.
|
Ok.
Quote:
Originally Posted by sawce
I'm fairly certain get_players would technically be faster
|
You are correct, sir.
Here's an example, but your mileage may vary depending on your specific applications. If you give me some ideas, then I might test them. According to the results of this test, get_players() is one order of magnitude faster than iterating through each client.
I had 32 bots connected to my server at the time of this test.
Code:
date: Thu Apr 16 23:59:26 2009 map: de_dust
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000001 / 0.000001 / 0.000001
n | get_maxplayers | 1 | 0.000000 / 0.000000 / 0.000000
n | register_srvcmd | 1 | 0.000066 / 0.000066 / 0.000066
n | server_cmd | 1 | 0.000003 / 0.000003 / 0.000003
n | is_user_connected | 320000 | 0.096525 / 0.000000 / 0.000064
n | get_players | 10000 | 0.006736 / 0.000001 / 0.000042
p | cmd_go | 1 | 0.006293 / 0.006293 / 0.006293
p | plugin_init | 1 | 0.000002 / 0.000002 / 0.000002
f | IterateThroughAllPlayers | 10000 | 0.108971 / 0.000010 / 0.000211
f | UseGetPlayers | 10000 | 0.009358 / 0.000001 / 0.000042
0 natives, 0 public callbacks, 2 function calls were not executed.
TOTAL TIME FOR:
IterateThroughAllPlayers
0.205496
UseGetPlayers
0.016094
PHP Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Get Players"
#define AUTHOR "stupok"
#define VERSION "1.0"
new g_iMaxPlayers
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_iMaxPlayers = get_maxplayers()
register_srvcmd( "go", "cmd_go" )
}
public cmd_go()
{
for( new i = 0; i < 10000; i++ )
{
IterateThroughAllPlayers()
}
for( new i = 0; i < 10000; i++ )
{
UseGetPlayers()
}
server_cmd( "quit" )
}
IterateThroughAllPlayers()
{
for( new i = 1; i <= g_iMaxPlayers; i++ )
{
if( is_user_connected( i ) )
{
//
}
}
}
UseGetPlayers()
{
static aPlayers[32], iPlayersNum, id
get_players( aPlayers, iPlayersNum, "" )
for( new i = 0; i < iPlayersNum; i++ )
{
id = aPlayers[i]
}
}
__________________