View Single Post
stupok
Veteran Member
Join Date: Feb 2006
Old 04-17-2009 , 01:08   Re: amxmodx profiler
Reply With Quote #37

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

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

IterateThroughAllPlayers()
{
    for( new 
1<= g_iMaxPlayersi++ )
    {
        if( 
is_user_connected) )
        {
            
//
        
}
    }
}

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

__________________

Last edited by stupok; 04-17-2009 at 01:12.
stupok is offline