Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does coding many small methods have performance ramifications for Objective-C?

I come from Ruby, and have sort of adopted the methodology of single responsibility principle, encapsulation, loose coupling, small testable methods, etc., so my code tends to jump from method to method frequently. That's the way I am used to working in the Ruby world. I argue that this is the best way to work, mainly for BDD, as once you start having "large" methods that do multiple things, it becomes very difficult to test.

I am wondering if there are any draw backs to this approach as far as noticeable differences in performance?

like image 494
patrick Avatar asked Aug 20 '12 01:08

patrick


People also ask

How to improve the performance of C++ code?

10 Tips for C and C++ Performance Improvement Code Optimization. 1. Optimize your Code using Appropriate Algorithm. For any code you write, you should always take some time to think through and pick the right ... 2. Optimize Your Code for Memory. 3. printf and scanf Vs cout and cin. 4. Using ...

How does Objective-C improve the quality of code?

Experience from the structured programming world had shown that one of the main ways to improve code was to break it down into smaller pieces. Objective-C borrowed and extended the concept of categories from Smalltalk implementations to help with this process. [25] Furthermore, the methods within a category are added to a class at run-time.

What is the difference between Objective-C and C programming language?

In Objective-C, a message is sent to the class at run-time and is resolved while the application is running. So in Objective-C, the called method has complete control over how to handle the action. But in the other C languages, it's hard-coded when the application is compiled. What is the C programming language?

Why should you learn coding standard best practices in C #?

In this article, you will learn coding standard best practices in C#. Nowadays, performance and security are very crucial aspects of business prospects. If your product is not good in performance and not secure as well, then you are certainly going to lose your reputation. Performance and security give a positive impact towards, Reputation etc.


1 Answers

Yes, there will always be some amount of performance impact unless you have a compiler that inlines things, but if you do dynamic method lookup (like Ruby and Obj-C), you can't inline, and so there will be some impact. However, it really depends on the language and the calling conventions. If you have a call in Objective-C, you know that the overhead will be the overhead of of using the C calling conventions once (calling objc_msg_send), then a method lookup, and then some sort of jump (most likely also C calling conventions, but could be anything). You have to remember, though, that unless you're writing C and assembly, it's almost impossible to see any difference.

like image 109
Linuxios Avatar answered Oct 12 '22 07:10

Linuxios