home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11376 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  2.2 KB

  1. Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!microsoft.com!jimad
  2. From: jimad@microsoft.com
  3. Newsgroups: comp.lang.c++
  4. Date: 18 Jul 92 00:06 MDT
  5. Subject: Re: virtual call efficiency (Re: ar
  6. Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
  7. Message-ID: <1992Jul17.200654.16033@microsoft>
  8. References: <9219919.15720@mulga.cs.mu.oz.au>
  9. Nf-ID: #R:9219919.15720@mulga.cs.mu.oz.au:-1880726321:1992Jul17.200654.16033@microsoft:2132721639:001:1708
  10. Nf-From: microsoft.com!jimad    Jul 18 00:06:00 1992
  11. Lines: 39
  12.  
  13.  
  14. In article <1992Jul16.184747.28930@cmcl2.nyu.edu> checker@acf3.nyu.edu (Christopher Hecker) writes:
  15. |I'm curious, have you timed the virtual call mechanism on your C++
  16. |compiler and compared it to the static call mechanism?  I would be
  17. |interested in seeing the results that forced you to make the above
  18. |decision; when I did timings on my compiler I discovered only a 10%
  19. |difference.  The test was on an empty function body for both virtual and
  20. |static functions, so in real code the difference would be much less than
  21. |that observed for a null function body.
  22.  
  23. The general "rule of thumb" is that the overhead for various kinds
  24. of function calls in C++ is *about* as follows:
  25.  
  26. call-type        overhead-cost
  27. ---------         -------------
  28.  
  29. inline               0
  30. non-virtual           1
  31. virtual               2
  32.  
  33. where "overhead-cost" has been normalized to be expressed in units of
  34. what it "normally" would cost to do a function call on your particular
  35. machine.
  36.  
  37. Depending on what one is doing then, one can find results where using
  38. an inline function is "infinitely" faster than using "normal" non-virtual
  39. function call or virtual function call.  Or alternately one might find
  40. that using inlines only removes 1 unit of time costs from one's program.
  41. Just like going from virtual to non-virtual might only save you 1 unit
  42. of time.
  43.  
  44. The big win results if say in the main loop of your software all "normal"
  45. function calls are replaced with inlines, replacing an N*1 or N*2 cost
  46. with a N*0 cost.  Of course, in a "real" inline function chances are
  47. the actual actions of that inline function do not come at "0" cost --
  48. but in many cases the actions that inline function performs *are* very
  49. inexpensive compared to the cost of a function call.
  50.  
  51.  
  52.