• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

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 65
Joined
Jan 18, 2005
Messages
27,296
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