Article View: comp.sys.mac.oop.macapp3
Article #47Re: Performance tests...
From: Alger, Jeff,VCA
Date: Mon, 28 Dec 1992 18:15
Date: Mon, 28 Dec 1992 18:15
49 lines
2687 bytes
2687 bytes
Richard,
Sigh. I wish this old saw about OOP performance would just go away. Here is
the truth:
1. OOP programs are considerably smaller than non-OOP programs (1/4 to 1/10,
depending on whose study you read). In addition to direct performance
benefits (i.e., less swapping) this means it is easier to get your mind around
the entire program. The result is usually better algorithms, which will always
swamp any language-derived factor.
2. OOP languages allow a compiler, carefully crafted and optimized, to handle
this sort of logic (please excuse me dropping into C rather than Pascal):
switch (aBlob->fType) {
case kTypeA: ...
case kTypeB: ...
...
}
Anyone ever look at the code produced by your average C or Pascal compiler for
this sort of conditional logic? It isn't pretty and it also isn't fast. Yet
this sort of branching is all over the place in procedural code. A compiler
will almost always do better than a programmer in such circumstances. Put
another way, in large part OOP compilers take on the task of writing code you
yourself would otherwise have to write but they do it FASTER and SMALLER, not
slower and bigger.
3. If you really want speed, use C++, not Pascal. I'm not going to debate the
merits of the two languages here other than to note that Pascal's dispatching
scheme is more compact but slower. One of the explicit design objectives of
C++ was to be as efficient as C unless you use polymorphism, and even then to
use the fastest dispatch scheme of all the major OOP approaches. That is, you
can recast a C program as a C++ program with non-virtual methods and have
IDENTICAL performance characteristics but considerably better-structured code.
And if you use polymorphism, C++ will run at least as fast as anything else.
As an indication, the switch-case logic above would be dispatched with (I
think) two extra machine instructions per case compared to simple function
calls and many, many times faster than a real switch-case.
It is unfortunate that so many people in the MacApp community have been blinded
by MacApp's relative slowness and size (there are valid reasons for both, but
due to how much MacApp does) into thinking OOP generally is slow and big when
generally the opposite is true.
Regards,
Jeff Alger
SBM International
Technical Details
Message-ID:
<725566624.2601446@AppleLink.Apple.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!olivea!apple!applelink.apple.comShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!olivea!apple!applelink.apple.com From: ALGER@AppleLink.Apple.COM (Alger, Jeff,VCA) Newsgroups: comp.sys.mac.oop.macapp3 Subject: Re: Performance tests... Message-ID: <725566624.2601446@AppleLink.Apple.COM> Date: 28 Dec 92 18:15:00 GMT Sender: daemon@Apple.COM Organization: AppleLink Gateway Lines: 49