• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

[JASS] Efficiency

Status
Not open for further replies.
Level 20
Joined
Jul 6, 2009
Messages
1,885
I was wondering what way of enumerating units is more efficient:
1. Enumerating a unit group using GroupEnumUnitsInRange and doing all actions within filter with filter always returning false.
2. Adding units to a unit group variable and looping through units by picking a random unit in group,executing actions and removing the unit from group.

I heard that using loop instead of group enumeration is more efficient, which is, i guess, the second way o_O
Or is there a more efficient way than these two?
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Thanks for response.
Still, Bribe said that it's better to use loop than group enumeration in a comment on one of my spells; i guess he meant the ForGroup enumeration.
So how would i do a loop instead of using ForGroup since it's not a dynamic enumeration, i want to keep units grouped so removing them wouldn't work?
 
Last edited:
Two things need to be distinguished.

1. The replies you've gotten in this thread appear to be based on the thought you would only be enumerating these units once, and not repeatedly. So they thought you meant this:

JASS:
call GroupEnum...
loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    call GroupRemoveUnit(g, u)
    //Actions
endloop

But since you reference these again and again, many times, you could use a different data structure - store each instance into an array slot, and loop through that array.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Two things need to be distinguished.

1. The replies you've gotten in this thread appear to be based on the thought you would only be enumerating these units once, and not repeatedly. So they thought you meant this:

JASS:
call GroupEnum...
loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    call GroupRemoveUnit(g, u)
    //Actions
endloop

But since you reference these again and again, many times, you could use a different data structure - store each instance into an array slot, and loop through that array.

While this kind of loop is neat coz you don't split the code, i hardly believe that is more efficient than directly coding inside the filter of GroupEnum.
But it shouldn't matter thought, since this kind of loop is for unique usage.

And yes i'm agree an array defined inside the GroupEnum should be better here.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
In a situation where you have tons and tons of local variables that all need to be referenced during the group-pick process, a FirstOfGroup loop can be faster. Otherwise I agree, a ForGroup should always be replaced by an inlined Filter when they can do the same thing (filter returning false).

Ok let's say "in any real scenario" if you care that much :p
 
Status
Not open for further replies.
Top