HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GetTriggerUnit() vs locals

02-01-2008, 10:58 AM#1
cohadar
What is more efficient:

Collapse JASS:
set temp = GetTriggerUnit()
set i = 0
loop
    exitwhen i >= ShieldCounter
    if GetUnitAbilityLevel(temp, ShieldId[i]) > 0 then
        call TriggerExecute(ShieldTrigger[i])
    endif
    set i = i + 1
endloop      

Collapse JASS:
set i = 0
loop
    exitwhen i >= ShieldCounter
    if GetUnitAbilityLevel(GetTriggerUnit(), ShieldId[i]) > 0 then
        call TriggerExecute(ShieldTrigger[i])
    endif
    set i = i + 1
endloop  

I know a lot of you would say the first one:
but what if GetTriggerUnit() native call is somehow inlined by the jass virtual machine? After all it is the most used native of all.

PipeDream?
02-01-2008, 11:03 AM#2
MaD[Lion]
interesting idea, but the difference wont be tat huge anyway
02-01-2008, 11:10 AM#3
grim001
correct answer: does not matter
02-01-2008, 11:41 AM#4
Vexorian
You are comparing GetTriggerUnit + local vs. only GetTriggerUnit, it does not really matter what the vm does.

If you would use GetTriggerUnit 4 times or more in the function, I am quite sure that the local would be faster, at least that's what benchmarks showed.
02-01-2008, 12:33 PM#5
cohadar
Quote:
Originally Posted by Vexorian
If you would use GetTriggerUnit 4 times or more in the function, I am quite sure that the local would be faster, at least that's what benchmarks showed.

Well that is what I was asking for, the benchmark.
kk then will use locals. (for 4 or more times :D)
02-01-2008, 01:19 PM#6
Vexorian
heh I didn't initially notice it was inside a loop.

Edit: And it actually matters if you have 20 GetTriggerUnit() inside an animation timer.
02-02-2008, 05:25 PM#7
Toadcop
well for small loop amount globals ruls 8-)
<=~10 operations, global var would be faster.
and + ofc to call a function is slower than to get data from variable (but well in war3 case it's a hash table element.)
02-02-2008, 10:44 PM#8
cohadar
wtf are you talking about?
Noone mentioned any globals.
02-02-2008, 11:27 PM#9
Toadcop
and ? i am talking about the best solution. who care what the other talking about ? =)
// btw the previous was my 1K post :beer:
02-02-2008, 11:35 PM#10
PipeDream
I think he means that it can be cheaper to use a global than declare a local.
02-03-2008, 12:52 AM#11
Vexorian
It could be , but it looks like it requires the special case of having few declared globals.