We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.
— Donald Knuth
Assuming none of the conditions have side-effects and essentially boil down to this:
If True And True And False Then
Then you're over-thinking it and are likely over-optimizing without any meaningful performance gains. Stop trying to squeeze out every nanosecond from your code, and write code that's easy to read, maintain, debug, and extend instead: if there's a performance bottleneck anywhere in your code, it's not here.
Context: I'm iterating through a sheet looking for an entry.
See, iterating through a sheet looking for an entry is your bottleneck. Interacting with a worksheet is hundreds if not thousands of times slower than interacting with an in-memory array.
So yes, because you're writing expensive code, lack of short-circuiting will make a difference, but not because short-circuiting is more a efficient use of Boolean logic - it will make a [potentially significant] difference because you'll be conditionally avoiding expensive worksheet reads.
If that sounds contradictory, you're not getting my point: the performance impact of short-circuiting Boolean logic on code that's already efficient, is largely insignificant.
Go on, try dumping the Range
you're iterating (and are you doing that with a For
or a For Each
loop? There's a massive difference between the two, depending on what you're doing) into a 2D array, and then use a For
loop to iterate it and look for your entry. I promise a much more noticeable performance improvement than anything you could get out of splitting your conditionals to simulate short-circuiting.
Or, perhaps re-evaluate whether you need to iterate anything at all. If you're looking for an entry, and depending on what your data looks like, you could combine the "condition columns" into one and use Application.WorksheetFunction.Match
to locate an entry without writing any loops or conditions.