Raised This Month: $ Target: $400
 0% 

attempting to optimize code


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-31-2016 , 12:56   Re: attempting to optimize code
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
Not even close to good. This is somewhat better:

PHP Code:
if(g_isalive[id])
{
    switch(
g_level[id])
    {
        case 
100 .. 199:
        {
            switch(
get_user_team(id))
            {
                case 
1cs_set_user_model(id"Model_1_T")
                case 
2cs_set_user_model(id"Model_1_CT")
            }
        }
        case 
200:
        {
            switch(
get_user_team(id))
            {
                case 
1cs_set_user_model(id"Model_2_T")
                case 
2cs_set_user_model(id"Model_2_CT")
            }
        }
    }

Don't ever do something like "100 .. 199", as that actually creates 100 entries in the jump table of the switch. Having just a simple "if" will probably be faster there. It's okay to use it when you are dealing with small ranges, like 10-20 or whatever, but not with hundreds. I believe that's the reason Bailopan switched off that feature in SourcePawn.

Quote:
Originally Posted by siriusmd99 View Post
yes?

how plugin works:

death - is_alive[id] = false;
disconnect is_alive[id] = false;
spawn - is_alive[id] = true;

native_is_user_alive(id)
return is_alive(id)


when you use is_user_alive(id), don't you get already cached value?

the thing is that when you use is_alive , you acces global array from plugin but when you call native is_user_alive, you call array from module, which is faster.
While module (C++) code will most likely run faster than pawn code, native calling is what is expensive and slow, at least compared to retrieving a value from an array.

Last edited by klippy; 05-31-2016 at 12:57.
klippy is offline
 



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 18:39.


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