There is one way that blocks could be faster:
- You use
NSEnumerationConcurrent
to enumerate the array.
- When you find an object that matches your condition, dispatch another block to a serial queue that adds the object to the result array. (You can't do this concurrently because NSMutableArrays are not thread safe.)
However, the documentation doesn't explicitly say that order will be preserved when enumerating concurrently. I think it's a good bet that it won't be. If the order of the array matters, you'd have to re-sort (if that's even possible), and you'd have to include that in any timing comparison.
The other ways are to non-concurrently enumerate using blocks and to filter using predicates. filterUsingPredicate:
could be faster, since NSArray will have the opportunity to use internal knowledge to build the result array faster than repeated addObject:
messages. But that's merely a possibility; the only way to know for sure would be to compare, and even then, the answer could change at any time (including in the same process, for different input arrays or different objects in the array).
My advice would be to implement it straightforwardly—using predicates—at first, and then use Instruments to see whether it's a performance problem. If not, clear code wins. If it is a performance problem, try concurrent enumeration.