RabinDev
RabinDev

Reputation: 658

C++ code run very slow in a predominantly Objective-c project

I was required to add an exotic image format to a project. The client supplied only a c++ library. The library does it's work extremely slow once compiled in a predominantly Objective-C project (that is, a project with all the rest of the code in objective-c)

I've compared performance with c++ implementations on a Mac and a PC, a ported C# implementation to a pc - all on computers similar to each other (CPU and memory-wise). The slow performance is only in the Objective-C project, much more evident on a device than on the simulator. I would expect a pentalty for the device's (iPad) less-than-mac/pc CPU, but not to go from 0.2 secs image parsing in the simulator to a staggering 2.4 secs per image on the device! Does all c++ code added to an Objective-C project perform so slow?

Tweaked with all compiler kinds, many compiler preferences. Also time-profiled to realize the c++ code takes huge amounts of time on trivial actions (simple instructions such as ++'s and +='s).

How should i approach this in order to get the c++ library's performance to a reasonable level within the objective-c project?

Upvotes: 2

Views: 279

Answers (1)

Caleb
Caleb

Reputation: 124997

I've compared performance with c++ implementations on a Mac and a PC, a ported C# implementation on a pc - all on similar computers CPU and memory-wise. The slow performance is only in an Objective-C project, much more evident on a device than on the simulator.

iOS devices are relatively powerful considering their size and battery constraints, but they're no match for a modern Mac or PC. You'd expect to find a significant slowdown of any code, C++ or otherwise, when running on a device compared to the simulator. When you say that you tested "all on similar computers" do you mean similar to each other or similar to, say, an iPhone 4?

I don't know of any particular performance penalty attached to using C++ together with Objective-C. You could test for yourself by coming up with some very simple benchmark, coding it in both C++ and Objective-C, and comparing execution times.

Upvotes: 7

Related Questions