View Single Post
stupok
Veteran Member
Join Date: Feb 2006
Old 04-18-2009 , 12:55   Re: amxmodx profiler
Reply With Quote #40

Quote:
Originally Posted by Emp` View Post
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(PLUGINVERSIONAUTHOR)
    
    
g_iMaxPlayers get_maxplayers()
    
    
register_srvcmd"go""cmd_go" )
}

public 
cmd_go()
{
    for( new 
01000000i++ )
    {
        
IterateThroughAllPlayers()
    }
    
    for( new 
01000000i++ )
    {
        
UseGetPlayers()
    }
    
    
server_cmd"quit" )
}

public 
client_authorizedid )
    
g_bClientConnected[id] = true

public client_disconnectid )
    
g_bClientConnected[id] = false

IterateThroughAllPlayers
()
{
    for( new 
1<= g_iMaxPlayersi++ )
    {
        if( 
g_bClientConnected[i] )
        {
            
//
        
}
    }
}

UseGetPlayers()
{
    static 
aPlayers[32], iPlayersNumid
    
    get_players
aPlayersiPlayersNum"" )
    
    for( new 
0iPlayersNumi++ )
    {
        
id aPlayers[i]
    }

__________________
stupok is offline