By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

Multiple inheritance performance hit

P: n/a
Does using multiple inheritance introduce any more performance overhead than
single inheritance?
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 30 Jul 2003 14:32:45 +0100, "Graham Banks"
<gr**********************************@sol-digi.com> wrote:
Does using multiple inheritance introduce any more performance overhead than
single inheritance?


It depends on the implementation, but calling a virtual function where
virtual multiple inheritence is involved will typically be slightly
slower than a normal virtual function. The vtable for a class involved
in multiple inheritence will probably be larger too.

Tom
Jul 19 '05 #2

P: n/a

"Graham Banks" <gr**********************************@sol-digi.com> wrote in message news:bg**********@newsg4.svr.pol.co.uk...
Does using multiple inheritance introduce any more performance overhead than
single inheritance?


Multiple inheritance vs. single inheritance
===========================================

C/C++ Performance Tests
=======================
Using C/C++ Program Perfometer
http://sourceforge.net/projects/cpp-perfometer
http://alexvn.freeservers.com/s1/perfometer.html
Environment
-----------
Windows 2000 Professional
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
Intel(R) Celeron(R) CPU 1.70 GHz
GNU gcc/g++ version 3.2 20020927 (prerelease)
Compilation : No optimization

===================== Classes : BEGIN =====================

====================
Hierarchy of classes
====================
Foo0
|
|
Foo1
|
|
_____________|_____________
| |
__________|__________ |
| | |
| | |
Foo2_v1 Foo2_v2 Foo2
| | |
|___________________| |
| |
| |
Foo3_m Foo3
| |
| |
Foo4_m Foo4

=====================
Definition of classes
=====================

// --------------
class Foo0
{
public:
Foo0 () {}
};

// --------------
class Foo1 : public Foo0
{
public:
Foo1 () : Foo0 () {}
};

// --------------
class Foo2_v1 : virtual public Foo1
{
public:
Foo2_v1 () : Foo1 () {}

};

// --------------
class Foo2_v2 : virtual public Foo1
{
public:
Foo2_v2 () : Foo1 () {}
};
// --------------
class Foo2 : public Foo1
{
public:
Foo2 () : Foo1 () {}

};

// --------------
class Foo3_m : public Foo2_v1, public Foo2_v2
{
public:
Foo3_m () : Foo1 (), Foo2_v1 (), Foo2_v2 () {}

};

// --------------
class Foo3 : public Foo2
{
public:
Foo3 () : Foo2 () {}

};

// --------------
class Foo4_m : public Foo3_m
{
public:
Foo4_m () : Foo1 (), Foo3_m () {}
};

// --------------
class Foo4 : public Foo3
{
public:
Foo4 () : Foo3 () {}
};

===================== Classes : END =======================

================ Performance tests : BEGIN ================

==================
Creating instances
==================
Summary test results
====================
#----------------------------------------------------------
# Comparison : multiple inheritance vs. single inheritance
#----------------------------------------------------------
# Resource Name : user time used (via rusage)
# Resource Cost Unit : milliseconds (unsigned long long)
# Resource State Unit : timeval
#----------------------------------------------------------
: ---------------------------------------------
: Foo0 : Level-0 base class -> 9
:
: Foo1 : Level-1 single inheritance -> 13
:
: Foo2 : Level-2 single inheritance -> 20
: Foo2_v1 : Level-2 virtual inheritance -> 20
: Foo2_v2 : Level-2 virtual inheritance -> 20
:
: Foo3 : Level-3 single inheritance -> 25
: Foo3_m : Level-3 multiple inheritance -> 42
:
: Foo4 : Level-4 single inheritance -> 32
: Foo4_m : Level-4 multiple inheritance -> 45
: ---------------------------------------------
Raw Log : http://groups.google.com/groups?selm....uni-berlin.de

================ Performance tests : END ==================
Regards,
=====================================
Alex Vinokur
mailto:al****@connect.to
http://mathforum.org/library/view/10978.html
=====================================
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.