mardi 2 décembre 2014

Performance of Class methods vs singleton instance methods


In my app, I'm using both strategies:




  1. I have a Utils class, it only has class methods that I call for doing common global methods, like NSString validation, etc.




  2. I have an app-wide singleton class which I instantiate during app Did Finish Launching, and use this throughout the app to hold global objects / state, perform long-running processes, etc.




My question is, in the terms of performance which approach is better? I'm happy with both the approaches, but I can do an inexpensive, but effortful migration to move all the Utils class methods to instance methods in the app-wide singleton if this would give me performance gains. The Utils methods get called a lot in my app, but I don't really notice any performance penalties in Instruments.


Likewise, I can go the other way and move at least a few of the somewhat general purpose functions I end up adding to the singleton to now be class methods in the Utils class as well.


Does any Objective-C guru have some concrete benchmarks or even strong opinions on which approach is more performant?





Aucun commentaire:

Enregistrer un commentaire