Which is more efficient? The biggest difference is you can't cancel dispatch_after blocks from executing while you can with NSTimer. So which is better: a large number of dispatch_after blocks that can't be canceled or a large number of NSTimers that will be canceled when possible?
Asked
Active
Viewed 230 times
3
-
3Benchmark your scenario and go with whatever seems best. It is unlikely that the performance characteristics greatly favor one over the other, so you need to weigh the other considerations after having hard data. – Avi Aug 18 '16 at 17:14
-
How would I go about benchmarking the two? – Tony Friz Aug 18 '16 at 17:15
-
@TonyFriz: I suggest that you use Xcode's [unit testing features](https://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/UnitTesting.html). – Vatsal Manot Aug 18 '16 at 17:30
-
I see XCTest incudes performance testing but how does that help me measure the difference between a lot of timers vs a lot of dispatch blocks? I want to see how a bunch of scheduled timers hurts the app in general. Is there a way to test that with unit testing? – Tony Friz Aug 18 '16 at 18:40
-
I could measure the part of actually scheduling the timers but isn't there still a deficit while they're waiting to fire? – Tony Friz Aug 18 '16 at 18:50