|
From: | Graham Lee |
Subject: | Re: speed of Obj-C vs. C++(slightly OT) |
Date: | Tue, 22 Apr 2003 10:12:53 +0100 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312 |
Jim McLoughlin wrote:
Hi Drik On Tuesday, April 22, 2003, at 01:36 AM, Dirk Theisen wrote:You can always include C libraries for maximum speed.AFAIK, some computational finance libs are in plain C anyway so you can get by with using C for the computations and ObjC for the rest (where message passing times do not matter).Thanks for the response. I realized after posting that it all depends on how you split things up between C/C++ or C/Obj-C.I guess my question is that, assuming these ratios are equal, which is faster.
C++. The reason is that C++ is *not* an Object-Oriented language, it has structs and it has functions. When you have a method in C++ (such as myClass.doSomething(withThis);), the method is resolved at *compile time* into a standard ol' C function call, which probably takes all of around four cycles for a function that takes no arguments, and uses about the same number to leave if the function returns void. Objective-C, on the other hand, does support OOP, including dynamic message lookup at runtime. This is why, in Objective-C, it is possible to change the target of a message while the program is running. This then requires a longer time to look up messages, in that they actually have to be looked up. I *think* this takes around 25 cycles per message call (a test I did with the GNU runtime on i686 suggests this).
It is possible to speed this up slightly, by caching message calls or even by calling objc_msgsend() directly. However once you do this, you'll probably find it easier and just as fast to write your code in C++ or straight C. Although what's a couple of dozen CPU cycles every now and then? The only situation you might find it to be a bind would be in highly recursive code.
-- Graham Lee, Wadham College, OX1 3PN
[Prev in Thread] | Current Thread | [Next in Thread] |