Yes, well-written C ++ is much faster. If you write performance-critical programs, and your C ++ is not as fast as C (or a few percent), something is wrong. If your ObjC implementation runs as fast as C, then something is usually wrong - that is, the program is probably a bad example of ObjC OOD because it probably uses some dirty tricks to step below the level the abstraction in which he works, for example, direct ivar.
Comparing Mike Ashe "is very misleading - I would never recommend an approach to comparing the runtime of the programs you wrote, or recommend comparing C vs C ++ with ObjC. The presented results are provided from a test with disabling compiler optimization. A program compiled with disabled optimizations are rarely relevant when you measure the runtime.To view it as a reference, which compares C ++ with Objective-C, is a drawback.The test also compares individual functions, not whole ones realistic implementations - individual functions are combined in different ways with both languages. This is far from a realistic performance test for optimized implementations. Examples. When optimization is enabled, the IMP cache is as slow as calling virtual functions. Static dispatch (unlike dynamic sendings, for example, using virtual ) and calls to known C ++ types (where dynamic sending can be bypassed) can be optimized aggressively. This process is called devirtualization, and when used, the member function declared virtual may even be inline d. In the case of the Mike Ash test, where many calls are made with member functions that have been declared virtual and have empty bodies: these calls are fully optimized when the type is known, because the compiler sees the implementation and can determine if a dynamic dispatch is needed. The compiler can also eliminate malloc calls in optimized builds (in favor of stack storage). Thus, the inclusion of compiler optimizers in any of C, C ++, or Objective-C can lead to significant differences in runtime.
Not to say that the results presented are absolutely useless. You can get useful information about external APIs if you want to determine if there are measurable differences between the time they spend in pthread_create or +[NSObject alloc] on one platform or architecture compared to another. Of course, these two examples will use optimized implementations in your test (unless you are developing them). But to compare one language with another in the programs you compile ... the presented results are useless when optimizations are disabled.
Object Creation
Consider also creating an object in ObjC - each object is allocated dynamically (for example, on the heap). With C ++, objects can be created on the stack (for example, about as fast as creating a C structure and calling a simple function in many cases), on the heap, or as elements of abstract data types. Each time you allocate and release (for example, via malloc / free), you can enter a lock. When you create a C struct or C ++ object on the stack, locking is not required (although internal members can use heap allocation), and it often costs just a few instructions or a few instructions plus a function call.
In addition, ObjC objects are reference counted instances. The actual need for an object to be std::shared_ptr in critical C ++ performance is very rare. In C ++, it is not necessary or desirable to make each instance a shared instance with reference counting. You have much more control over ownership and lifetime with C ++.
Arrays and Collections
Arrays and many collections in C and C ++ also use strongly typed containers and continuous memory. Since the address of the next element members is often known, the optimizer can do much more, and you have a lot of cache and memory. With ObjC, which is far from reality for standard objects (for example, NSObject ).
Dispatch
Regarding methods, many C ++ implementations use several virtual / dynamic calls, especially in highly optimized programs. These are static method calls and optimizer feeds.
Using ObjC methods, each method call (sending an objc message) is dynamic and therefore is a firewall for the optimizer. Ultimately, this leads to many limitations or inconveniences regarding what you can and cannot do to maintain performance at least when writing critical ObjC. This can lead to larger methods, IMP caching, frequent use of C.
Some real-time applications cannot use any ObjC messaging in their visualization paths. No - sound rendering is a good example of this. Submitting ObjC is simply not intended for real-time purposes; Highlighting and blocking can occur behind the scenes during messaging, which makes objc's complexity / messaging time unpredictable so that audio and video can miss its deadline.
Other functions
C ++ also provides generic / template implementations for many of its libraries. They are very well optimized. They are typical, and many investments and optimizations can be done using templates (consider its polymorphism, optimization and specialization that occur during compilation). C ++ adds several functions that are simply not available or comparable in strict ObjC. Trying to directly compare langs, objects and libraries, which are very different, is not so useful - this is a very small subset of real implementations. It is better to expand the question to a library / framework or a real program, taking into account many aspects of design and implementation.
Other points
Symbols C and C ++ can be easily removed and optimized at different stages of assembly (deletion, deletion of dead code, embedding and early insertion, as well as optimization of communication time). Benefits of this include reduced binary sizes, reduced startup / boot time, reduced memory consumption, etc. For one application, this may not be so important; but if you reuse a lot of code, and you should, then your shared libraries could add a lot of extra weight to the program, if implemented by ObjC - if you are not ready to jump over some flaming hoops. Thus, scalability and reuse are also factors in medium and large projects and groups where it is reused.
Included Libraries
ObjC library developers are also optimized for the environment, so its library developers can use some of the language and environment functions to offer optimized implementations. Despite some fairly significant limitations when writing an optimized program in pure ObjC, some highly optimized implementations exist in Cocoa. This is one of Cocoa's strengths, although the standard C ++ library (what some call STL) doesn't slouch either. Cocoa works at a much higher level of abstraction than C ++ - if you have a poor knowledge of what you are doing (or should do), working closer to the metal can really cost you. A return to a good library implementation if you are not an expert in some domain is good if you are really not ready to learn. In addition, Cocoa environments are limited; you can find implementations / optimizations that make better use of the OS.
If you write optimized programs and gain experience in C ++ and ObjC, pure C ++ implementations will often be twice as fast or faster than pure ObjC (yes, you can compare with Cocoa). If you know how to optimize, you can often do better than general abstractions. Although some optimized C ++ implementations will be as fast or slow as Cocoa (for example, my initial attempt to file I / O was slower than Cocoa - primarily because the C ++ implementation initializes its memory).
Many of them come down to language features that you are familiar with. I use both languages, they both have different strengths and models / patterns. They complement each other well, and there are large libraries for them. If you are running a complex performance-critical program, using the C ++ functions and libraries correctly will give you much more control and significant optimization benefits, so that in the right hands “several times faster” is a good default expectation (however, don't expect winning every time, or without any work). Remember that years are enough to understand C ++ to really reach this point.
I keep most of the critical working paths as C ++, but also acknowledge that ObjC is also a very good solution for some problems and that there are some very good libraries.