HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Most effienct way of referencing a unit = ?

08-24-2009, 05:30 PM#1
marshall
I want my map to be as efficient as possible in the basic code (not worrying about systems here, just plain Jass). I've searched around for tips on this but am not completely sure what the pros/cons are of the following snippets of code. Would someone mind pointing out the pros/cons of each of the following in terms of efficiency? Thanks.

Method A
Collapse JASS:
set udg_MyUnitArray[94] = GetTriggerUnit()
call PauseUnit(udg_MyUnitArray[94], true)
call IssueImmediateOrder(udg_MyUnitArray[94], "stop")
call PauseUnit(udg_MyUnitArray[iDynamic], false)

Method B
Collapse JASS:
local unit uTemp = GetTriggerUnit()
set udg_MyUnitArray[94] = uTemp
call PauseUnit(uTemp, true)
call IssueImmediateOrder(uTemp, "stop")
call PauseUnit(uTemp, false)
set uTemp = null

Method C
Collapse JASS:
set udg_MyUnitArray[94] = GetTriggerUnit()
call PauseUnit(GetTriggerUnit(), true)
call IssueImmediateOrder(GetTriggerUnit(), "stop")
call PauseUnit(GetTriggerUnit(), false)
08-24-2009, 05:34 PM#2
Vulcano
Collapse JASS:
call PauseUnit(GetTriggerUnit(), true)
call IssueImmediateOrder(GetTriggerUnit(), "stop")
call PauseUnit(GetTriggerUnit(), false)
method A if this isn't ok for you
08-24-2009, 05:35 PM#3
Rising_Dusk
Method B results in the cleanest code, and the speed differences between A, B, and C are negligible. Thus I would recommend using method B.
Collapse JASS:
function MyFunc takes nothing returns nothing
    local unit u = GetTriggerUnit()

    call PauseUnit(u, true)
    call IssueImmediateOrder(u, "stop")
    call PauseUnit(u, false)

    set u = null
endfunction
08-24-2009, 05:36 PM#4
Alevice
method A has to do an array lookup. method B consumes an extra vraible. and method c has to make loads of function calls. the least of the evils is method b.
08-24-2009, 05:38 PM#5
marshall
Thanks guys that's most helpful. I didn't mention that I need the array elsewhere so, given that I have to have the array set anyway, would that make A better than B?
08-24-2009, 10:45 PM#6
Zerzax
Not really, B is still better because of organization while A requires array lookup. I think everyone already factored in the need to set the unit as part of the array ;)
08-24-2009, 10:53 PM#7
Earth-Fury
Quote:
Originally Posted by marshall
Thanks guys that's most helpful. I didn't mention that I need the array elsewhere so, given that I have to have the array set anyway, would that make A better than B?

The difference between A and B would amount to the difference in the weight of two coins of the same denomination selected at random.

The secret to truly fast JASS code: reduce function calls to a minimum. The only places where Truly Fast JASS™ will make any kind of noticeable difference will be in iterative or recursive shit which recurses/iterates a large number of times. Trying to optimize a function that's called maybe once every 5 seconds will sooner drive you insane then it will actually make any kind of measurable difference.
08-24-2009, 11:37 PM#8
Anitarf
This thread is so 2006.

Like people have already pointed out, the speed difference between the methods is absurdly small, practically nonexistant, so in this case readability definitely trumps efficiency.
08-25-2009, 05:26 PM#9
marshall
Thank you all, really cleared things up for me :)
And apologies if this was already well known stuff!
08-25-2009, 08:04 PM#10
Anitarf
Quote:
Originally Posted by marshall
And apologies if this was already well known stuff!
It's not that it's well known, it's just that people have learned not to care about it. I mean, sure, we sometimes give people a hard time about petty efficiency improvements in the submission section but that's usually only the case when we don't like their spell in general, not because we would think having one less local declaration will dramatically improve the speed of the spell.