• 🏆 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!

Loop Question

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
1-100 would be better since the loop structure is just overhead. Your trigger option would be obnoxiously slower. If you end up having an if i > 10 then else if i > 20 then else if i > 30... than theres an issue in ur coding style.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
More threads means more overhead.
More loop structures means more overhead.

What executes the fastest in this case is to actually get rid of the loop. No loop means no overhead. Instead you repeat the loop code as many times as you intended to loop it. This is called loop unwinding and many good modern compilers do it automatically for simple loops (JASS does not count as that is rubbish).

What is the easiest to write/maintain is using a loop. It condenses the functionality into a single block as opposed to repeating it loop number of times.

The only time you would want different loops in sequence is if you want certain behaviour done within a certain range (SHA-1 is a good example of where this could apply). Instead of having to define certain test ranges to determine the behaviour to run you can instead run the loop up until the behaviour change boundary and then go on to another loop with another behaviour. This trades off readability and maintainability for performance by lowering conditional overhead each loop iteration.

In WC3 there is something called an op-limit. This limits the total complexity of the script a single thread can execute instantly. As such there is a limit to loop size based on the complexity of the loop block and the amount of op-limit available for it. This only applies to really massive loops or loops that perform highly complicated tasks.
 
Status
Not open for further replies.
Top