HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Tiny efficiency question

12-01-2003, 04:59 AM#1
Garu
This may be an incredibly stupid question, but it popped into my head and it might help me boost performance on my map. Basically, I want to know which is more efficient: performing an action for each unit in a group, or simply counting the units in the group and then performing a "for each" routine up to that value.

Let me pose two triggers:
Trigger A
A: Unit Group - Pick every unit in UnitGroupX and do (Actions)

Trgger B
A: Set N = (Number of units in (Units in (UnitGroupX)))
For each (Integer A) from 1 to N, do (Actions)

Trigger A has fewer actions, but I'd imagine it might be slower for the computer to keep track of which units its counted and which it hasn't. It's obviously a lot more flexible, but that isn't the issue. B has more actions, but they're quite a bit simpler. I realize that in 99% of instances this difference wouldn't matter at all, but I might have some situations that require cycling actions for huge groups, and every bit of performance I can salvage is useful. Sure, you may not need the answer to this right now, but when you decide to calculate the Fibonacci numbners up to the number of footmen you have on the map, you'll be glad we cleared this little issue up.
12-01-2003, 06:18 AM#2
Ligature
I believe in your examples, Trigger A would be best used for methods that involved actually doing something to the units or getting information about the units, while Trigger B would be better used for methods that just dealt with the number of units... Not a lot of situations where that happens, that I've run into, but in theory I think it would have a slight performance edge.
12-01-2003, 07:29 AM#3
Neo_Genesis
The two triggers are almost the same thing, one just has an extra step and a diffrent referance type. Becuase trigger B could become:

Trgger B
For each (Integer A) from 1 to (Number of units in (Units in (UnitGroupX))), do (Actions)

And work just like Trigger A. I recomend Trigger A over Trigger B though as its faster (for me anyhow) to use the picked unit commad over Integer A. In fact I'm not really sure how you would referance a unit with Integer A in a group unless you put it in an array of some kind.

So I would say trigger A =p

Neo_Genesis