home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / oop / macapp3 / 302 < prev    next >
Encoding:
Internet Message Format  |  1992-12-28  |  2.6 KB

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