spyderblack723 407 Posted February 10, 2017 Note that whether not you are looping over the whole array or using a select CODE statement allunits select {(side _x) == CIVILIAN} You are still filtering the array either way. One way may still be faster than the other due to less statements in SQF -- more done engine side etc. Essentially, all that does is loop over the array and remove any units that arent civilian, the new array is then fed to your foreach statement for another loop. Count is faster than foreach, minimally in most cases. If your loop doesn't have many statements though, profile it with both count and foreach and you may see some significant differences. my general suggestions.. Profile stuff, not just entire loops and blocks of code, but very basic stuff. The more you do this, the more comfortable you will get with choosing X over Y in terms of performance. Less/shorter code does not mean faster. Just because you throw 3 long blocks of code in functions and reduce your script to 3 lines does not mean it's any faster. Always be aware of the inner workings of what your invoking (to a reasonable limit) and not just blindly calling functions. Keep your variables defined in the lowest necessary scope, the keyword use of private (private var = value) helps "promote" this. To tack on to the above, always private your variables. Use unscheduled scope (call instead of spawn)(non-suspendable) as much as possible. This will ensure your code runs quickly and doesn't disturb the scheduler. If your code is too heavy, it might have to reside in an unscheduled scope (spawn) to avoid causing the game to freeze/stutter. (You can also split work by frames, this could be too complicated depending on your skill level, just know it's an option to explore) 1 Share this post Link to post Share on other sites
fn_Quiksilver 1636 Posted February 10, 2017 1 hour ago, spyderblack723 said: If your code is too heavy, it might have to reside in an unscheduled scope (spawn) to avoid causing the game to freeze/stutter. fixed Share this post Link to post Share on other sites
spyderblack723 407 Posted February 10, 2017 8 hours ago, fn_Quiksilver said: fixed Oops, good catch, thanks. Share this post Link to post Share on other sites