Raised This Month: $32 Target: $400
 8% 

[TUT] Modules and efficient scripting


Post New Thread Reply   
 
Thread Tools Display Modes
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 04-20-2009 , 14:25   Re: [TUT] Modules and efficient scripting
Reply With Quote #91

"When there a 32 slots on the server.. MAX_ENTs = 1365"

fail,
maxents = 900 + maxplayers * 15
maxents_32 = 900 + 32 * 15 = 1380

anyway, thats the hl calculations which is used if the -num_edicts param is not used, else maxents = -num_edicts
__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 04-20-2009 , 14:29   Re: [TUT] Modules and efficient scripting
Reply With Quote #92

Quote:
Originally Posted by Empowers View Post
why? g_isAlive is a good optimization & it's pretty save:
PHP Code:
//code by MeRcyLeZZ
public fw_PlayerSpawnid )
{
    if ( !
is_user_aliveid ) || !cs_get_user_teamid ) )
        return;
    
    
g_isAlive[id] = true
}

public 
fw_PlayerKilledid )
{
    
g_isAlive[id] = false

Running two forwards like that is probably slower than just using is_user_alive() wherever you need it (unless you're checking it in client_PreThink or some other forward that's called very frequently). This is even more likely since you have two native calls in the fw_PlayerSpawn() function. On top of that, you lose precision as the player could have been marked as killed some other way (although unlikely).

Either way, it's a trivial optimization, even if it was faster. People need to learn how to balance their time. Your plugin doesn't have to be 100% optimized to the point that not a single CPU cycle is wasted. Just apply optimizations that don't make you go extremely out of your way to do them. This, for example, is an insanely big waste of time.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-20-2009 , 14:31   Re: [TUT] Modules and efficient scripting
Reply With Quote #93

Hawk is alive!
__________________
joaquimandrade is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 04-20-2009 , 17:19   Re: [TUT] Modules and efficient scripting
Reply With Quote #94

This:
PHP Code:
static cell AMX_NATIVE_CALL strip_user_weapons(AMX *amxcell *params// index
{
    
CHECK_PLAYER(params[1]);

    
edict_tpPlayer MF_GetPlayerEdict(params[1]);

    
string_t item MAKE_STRING("player_weaponstrip");
    
edict_t *pent CREATE_NAMED_ENTITY(item);
    
    if (
FNullEnt(pent)) 
    {
        return 
0;
    }

    
MDLL_Spawn(pent);
    
MDLL_Use(pentpPlayer);
    
REMOVE_ENTITY(pent);

    *
reinterpret_cast<int *>(MF_PlayerPropAddr(params[1], Player_CurrentWeapon)) = 0;

    return 
1;

Is the same like this.

PHP Code:
stock fm_strip_user_weapons(index) {
    static 
entent fm_create_entity("player_weaponstrip");
    if (!
pev_valid(ent))
        return 
0;

    
dllfunc(DLLFunc_Spawnent);
    
dllfunc(DLLFunc_Useentindex);
    
engfunc(EngFunc_RemoveEntityent);

    return 
1;

And have less things.

Module using module is more faster than a call of the plugin?

MDLL_Spawn Is a call in the module.
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-20-2009 , 17:22   Re: [TUT] Modules and efficient scripting
Reply With Quote #95

Quote:
Originally Posted by AntiBots View Post
This:
PHP Code:
static cell AMX_NATIVE_CALL strip_user_weapons(AMX *amxcell *params// index
{
    
CHECK_PLAYER(params[1]);

    
edict_tpPlayer MF_GetPlayerEdict(params[1]);

    
string_t item MAKE_STRING("player_weaponstrip");
    
edict_t *pent CREATE_NAMED_ENTITY(item);
    
    if (
FNullEnt(pent)) 
    {
        return 
0;
    }

    
MDLL_Spawn(pent);
    
MDLL_Use(pentpPlayer);
    
REMOVE_ENTITY(pent);

    *
reinterpret_cast<int *>(MF_PlayerPropAddr(params[1], Player_CurrentWeapon)) = 0;

    return 
1;

Is the same like this.

PHP Code:
stock fm_strip_user_weapons(index) {
    static 
entent fm_create_entity("player_weaponstrip");
    if (!
pev_valid(ent))
        return 
0;

    
dllfunc(DLLFunc_Spawnent);
    
dllfunc(DLLFunc_Useentindex);
    
engfunc(EngFunc_RemoveEntityent);

    return 
1;

And have less things.

Module using module is more faster than a call of the plugin?

MDLL_Spawn Is a call in the module.
It doesn't have more code. You are forgetting that fm_create_entity has more calls inside it.

Calling functions inside modules is less expensive than plugins calling module provided functions.
__________________
joaquimandrade is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-22-2009 , 08:02   Re: [TUT] Modules and efficient scripting
Reply With Quote #96

Just tested strip_user_guns and give_item vs fakemeta, and i was surprised about results..
Code:
                 name |      calls | time / min / max
--------------------------------------------------
                equal |       1001 | 0.001641 / 0.000001 / 0.000229
              engfunc |       6006 | 0.037257 / 0.000001 / 0.002556
            pev_valid |       2002 | 0.003879 / 0.000001 / 0.000697
                  pev |       4004 | 0.007338 / 0.000001 / 0.000470
              set_pev |       2002 | 0.003648 / 0.000001 / 0.000293
              dllfunc |       4004 | 0.126556 / 0.000002 / 0.003295
         fm_give_item |       1001 | 0.018707 / 0.000016 / 0.000473
fm_strip_user_weapons |       1001 | 0.012963 / 0.000008 / 0.000943

            give_item |       1001 | 0.307619 / 0.000152 / 0.016896
   strip_user_weapons |       1001 | 0.068136 / 0.000033 / 0.001293
0.001641 + 0.037257 + 0.003879 + 0.007338 + 0.003648 + 0.126556 + 0.018707 + 0.012963 = 0.211989
0.307619 + 0.068136 = 0.375755

Fun is slower with less calls?

PHP Code:
#include <amxmodx>
#include <fun>
#include <fakemeta_util>

new omg2;

public 
plugin_init() {
    
register_clcmd("say /profile","profile");
}

public 
profileid ) {
    
// set_Task because loop crushes server.
    
set_task0.1"omg"id,_,_,"b" );
}

public 
omgid ) {
    
omg2++;
    
strip_user_weaponsid );
    
fm_strip_user_weaponsid );
    
    
give_itemid"weapon_knife" );
    
fm_give_itemid"weapon_knife" );
    
    if( 
omg2 1000 )
        
server_cmd("quit");

Yeah my PC is slow.
__________________
xPaw is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 04-22-2009 , 08:14   Re: [TUT] Modules and efficient scripting
Reply With Quote #97

Run them separately. It's not fair the way you have it set up since fm_strip_user_weapons() and fm_give_item() have no work to do.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-22-2009 , 08:28   Re: [TUT] Modules and efficient scripting
Reply With Quote #98

U'r right. But still strip_user_weapons is slower...
Code:
                             name |      calls | time / min / max
-------------------------------------------------------------------
                          engfunc |       3003 | 0.018500 / 0.000002 / 0.001438
                        pev_valid |       1001 | 0.004189 / 0.000001 / 0.001656
                          dllfunc |       2002 | 0.015975 / 0.000002 / 0.000834
            fm_strip_user_weapons |       1001 | 0.012942 / 0.000008 / 0.000651

               strip_user_weapons |       1001 | 0.086086 / 0.000033 / 0.004615
-------------------------------------------------------------------
                            equal |       1001 | 0.003534 / 0.000001 / 0.001859
                          engfunc |       3003 | 0.016452 / 0.000002 / 0.001325
                        pev_valid |       1001 | 0.001539 / 0.000001 / 0.000400
                              pev |       4004 | 0.009467 / 0.000001 / 0.000779
                          set_pev |       2002 | 0.004025 / 0.000001 / 0.000494
                          dllfunc |       2002 | 0.157066 / 0.000002 / 0.004978
                     fm_give_item |       1001 | 0.032702 / 0.000016 / 0.002458

                        give_item |       1001 | 0.173836 / 0.000115 / 0.002795
-------------------------------------------------------------------

strip_user_weapons = 0.086086
fm_strip_user_weapons = 0.051606

give_item = 0.173836
fm_give_item = 0.224785

Someone make, strip_user_weapons & give_item || fm_strip_user_weapons & give_item
__________________

Last edited by xPaw; 04-22-2009 at 08:32.
xPaw is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-22-2009 , 13:39   Re: [TUT] Modules and efficient scripting
Reply With Quote #99

xPaw, tasks are not suitable for profiling it seems.

Edit: Of course they aren't. Profiling tasks is like profiling forwards. They are called from the module so you just can't do it.

PHP Code:

date
Tue Apr 21 18:38:46 2009 mapde_dust2
type 
|                             name |      calls time min max
-------------------------------------------------------------------
   
|                            equal |        100 0.000242 0.000002 0.000005
   n 
|                          engfunc |        300 0.001387 0.000002 0.000010
   n 
|                        pev_valid |        100 0.000269 0.000002 0.000004
   n 
|                              pev |        400 0.001077 0.000002 0.000004
   n 
|                          set_pev |        200 0.000563 0.000002 0.000027
   n 
|                          dllfunc |        200 0.002190 0.000003 0.000021
   n 
|                   register_clcmd |          0.000017 0.000017 0.000017
   n 
|                        give_item |        100 0.002403 0.000020 0.000084
   p 
|                      plugin_init |          0.000007 0.000007 0.000007
   p 
|                          profile |          0.000425 0.000425 0.000425
   f 
|                     fm_give_item |        100 0.003121 0.000028 0.000055
0 natives
public callbacksfunction calls were not executed
PHP Code:
dateTue Apr 21 18:40:26 2009 mapde_dust2
type 
|                             name |      calls time min max
-------------------------------------------------------------------
   
|                          engfunc |        300 0.001517 0.000002 0.000031
   n 
|                        pev_valid |        100 0.000281 0.000002 0.000004
   n 
|                          dllfunc |        200 0.001160 0.000002 0.000023
   n 
|                   register_clcmd |          0.000018 0.000018 0.000018
   n 
|               strip_user_weapons |        100 0.001220 0.000010 0.000022
   p 
|                      plugin_init |          0.000007 0.000007 0.000007
   p 
|                          profile |          0.000427 0.000427 0.000427
   f 
|            fm_strip_user_weapons |        100 0.001602 0.000014 0.000031
0 natives
public callbacksfunction calls were not executed
__________________

Last edited by joaquimandrade; 04-22-2009 at 21:13.
joaquimandrade is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 08-31-2009 , 21:51   Re: [TUT] Modules and efficient scripting
Reply With Quote #100

I thought the concept behind the fakemeta high was that the engine module eats up CPU time when it's doing nothing, whereas fakemeta does not. I haven't seen anyone do a profile with fakemeta running for long periods of time with the engine module disabled, versus engine running for long periods of time. In most profiles, I see the fakemeta being compared with the engine in the same plugin, which guarantees that the engine module is still running -- defeating the purpose of a comparison between engine and "pure fakemeta"; we've taken away the most preached aspect of the comparison: engine module uses CPU when it is not being used.

I'm not taking sides, because I'm not advanced enough of a scripter to really care, but I think these tests are less intuitive than they appear, and that if we are going to state things as solid facts with profiles, fair tests should be run.
__________________
Bad_Bud is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:31.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode