Multiple inheritance performance hit

G

Graham Banks

Does using multiple inheritance introduce any more performance overhead than
single inheritance?
 
T

tom_usenet

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
 
A

Alex Vinokur

Graham Banks said:
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/[email protected]

================ Performance tests : END ==================


Regards,
=====================================
Alex Vinokur
mailto:[email protected]
http://mathforum.org/library/view/10978.html
=====================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,138
Messages
2,570,801
Members
47,348
Latest member
nethues

Latest Threads

Top