| 02-27-2014, 10:37 PM | #1 |
At what point does it become better (read: faster) to use a local variable to store an event variable rather than using the function call? e.g. JASS:private function Actions takes nothing returns nothing local unit c = GetTriggerUnit() call IssueLastOrder(c) call UnitAddBuff(c, c, BUFF_TYPE_SOMETHING, DURATION, 1) set c = null endfunction JASS:private function Actions takes nothing returns nothing call IssueLastOrder(GetTriggerUnit()) call UnitAddBuff(GetTriggerUnit(), GetTriggerUnit(), BUFF_TYPE_SOMETHING, DURATION, 1) endfunction Is it after you would use the function X times or does it depend on other stuff? I know the first is less function calls but is that outweighed by having to create and null a local variable? |
| 02-28-2014, 06:35 AM | #2 |
benchmark it. |
| 02-28-2014, 07:32 AM | #3 |
Last time I benched it, it was 2 times. Local declaration is fast, and so is nulling it. So usually I'll call the same function within a function 2 times at most. iirc, the difference between something like this was pretty negligble: JASS:call BJDebugMsg(GetUnitName(GetTriggerUnit()) + GetUnitName(GetTriggerUnit())) // ... vs ... local unit u = GetTriggerUnit() call BJDebugMsg(GetUnitName(u) + GetUnitName(u)) set u = null (that code is just an example, not the actual code I used). I don't remember which one is necessarily faster. When you have 3 function calls vs. a local declaration, I'm 90% certain that the local declaration was the faster option. ... But all this is just from my memory, which can be foggy. Sadly, I can't test it (yay Macs). |
