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