HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Local variables V GetTriggerUnit()

02-27-2014, 10:37 PM#1
Fledermaus
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.
Expand JASS:
or
Expand JASS:

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
DioD
benchmark it.
02-28-2014, 07:32 AM#3
PurgeandFire111
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:
Collapse 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).