If there is already a thread about this I apologise now and expect this thread will no doubt be deleted accordingly.
http://wiki.amxmodx.org/index.php/Optimizing_Plugins
After being told about this optimizing plugins site (thankyou Suicid3
) I was hoping we could get some of the "pro" Pawn programmers to take time out of their busy schedules and answer some questions from the "inexperienced" programmers amongst us who sometimes wonder if their plugins are the cause of lag on their native servers.
I'll go first; Re-using variables.
The above site does not mention re-using variables so I was wondering, which of the two code fragments below is most efficient or better?
#1
Code:
new cc = ns_get_build ( "team_command" , 1 , 1 ) //Get CC index
new Float: fl_Tmp
fl_Tmp = entity_get_float ( cc, EV_FL_health ) //Get CC health
new ccHP = floatround ( fl_Tmp )
fl_Tmp = entity_get_float ( cc, EV_FL_max_health ) //Get CC max health
new ccMaxHP = floatround ( fl_Tmp )
fl_Tmp = (ccHP / ccMaxHP) * 100 //get CC health percentage
new ccPercent = floatround ( fl_Tmp )
#2
Code:
new cc = ns_get_build ( "team_command" , 1 , 1 ) //Get CC index
new Float:fl_ccHp = entity_get_float ( cc, EV_FL_health ) //Get CC health
new ccHp = floatround ( fl_ccHp )
new Float:fl_ccMaxHp = entity_get_float ( cc, EV_FL_max_health ) //Get CC max hp
new ccMaxHp = floatround ( fl_ccMaxHp )
new Float:fl_Percent = ( ccMaxHp / ccMaxHP) * 100 //get CC health percentage
new ccPercent = floatround ( fl_Percent )