Quote:
Originally Posted by Emp`
Try saving whether a player is connected into a global during client_authorized and client_disconnect.
|
Ok.
Caching the results of cient_authorized() and client_disconnect() increases the speed of IterateThroughAllPlayers() tremendously. Now, the get_players() method is one order of magnitude slower than iterating through each player.
Here are the results: (NOTE: the previous post had 10,000 iterations, this had 1,000,000 iterations)
Code:
32 BOTS, CACHED CONNECT/DISCONNECT
date: Sat Apr 18 11:46:00 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.000059 / 0.000059 / 0.000059
n | server_cmd | 1 | 0.000003 / 0.000003 / 0.000003
n | get_players | 1000000 | 0.660214 / 0.000001 / 0.001794
p | client_authorized | 32 | 0.000019 / 0.000001 / 0.000001
p | client_disconnect | 32 | 0.000010 / 0.000000 / 0.000000
p | cmd_go | 1 | 0.623259 / 0.623259 / 0.623259
p | plugin_init | 1 | 0.000002 / 0.000002 / 0.000002
f | IterateThroughAllPlayers | 1000000 | 0.604227 / 0.000001 / 0.001491
f | UseGetPlayers | 1000000 | 0.934782 / 0.000001 / 0.001892
0 natives, 0 public callbacks, 4 function calls were not executed.
TOTAL TIME FOR:
IterateThroughAllPlayers
0.604227
UseGetPlayers
1.594996
Here's the plugin:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Get Players"
#define AUTHOR "stupok"
#define VERSION "1.0"
new g_iMaxPlayers
new g_bClientConnected[33]
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 < 1000000; i++ )
{
IterateThroughAllPlayers()
}
for( new i = 0; i < 1000000; i++ )
{
UseGetPlayers()
}
server_cmd( "quit" )
}
public client_authorized( id )
g_bClientConnected[id] = true
public client_disconnect( id )
g_bClientConnected[id] = false
IterateThroughAllPlayers()
{
for( new i = 1; i <= g_iMaxPlayers; i++ )
{
if( g_bClientConnected[i] )
{
//
}
}
}
UseGetPlayers()
{
static aPlayers[32], iPlayersNum, id
get_players( aPlayers, iPlayersNum, "" )
for( new i = 0; i < iPlayersNum; i++ )
{
id = aPlayers[i]
}
}
__________________