2

How fast is if #available(iOS 13.0, *), or checking any iOS version? Is it as fast as a set bool?

Say if you have a real time camera effect running and every frame it checks using #available, is that more taxing than using a set boolean?

shim
  • 9,289
  • 12
  • 69
  • 108
Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90
  • 4
    Are you having a performance issue? Why are you checking the version for every frame? Why not check the version sooner if it's causing an issue? – rmaddy Sep 19 '19 at 18:49
  • I'm not sure if there's an issue or not, I just want an in depth explanation about its performance. – Chewie The Chorkie Sep 19 '19 at 18:54
  • 1
    A bool variable should be 'faster', by some small constant (ie. even making another method call or adding another comparison before the boolean check is likely 'slower'). If it matters or not.. probably going to go with 'not' in most cases, especially in context of code that actually 'does work'. From https://stackoverflow.com/questions/3339722/how-to-check-ios-version, I suspect it delegates down to UIDevice#currentVersion. – user2864740 Sep 19 '19 at 19:01
  • 2
    @MojtabaHosseini O(1) say *nothing* about wall-clock time. A text editor that takes exactly one second to respond to every keyboard stroke is still O(1). Not very fun to use. Likewise, and more to the question, if this call always took 100ms (so O(1)!), that would limit the maximum rate to 10 per second! Thankfully it is very much *faster*; it becomes then a question of relative performance to meaningful work. – user2864740 Sep 19 '19 at 19:09
  • Might have better luck in the [Swift Forums](https://forums.swift.org/) with this question. – shim Sep 19 '19 at 20:43

0 Answers0