473,748 Members | 7,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple inheritance performance hit

Does using multiple inheritance introduce any more performance overhead than
single inheritance?
Jul 19 '05 #1
2 4335
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

"Graham Banks" <gr************ *************** *******@sol-digi.com> wrote in message news:bg******** **@newsg4.svr.p ol.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****@c onnect.to
http://mathforum.org/library/view/10978.html
=============== =============== =======
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3291
by: Hung Jung Lu | last post by:
Hi, I think Microsoft did look into Python when they designed C#. (E.g. they got rid of checked exceptions of Java.) However, they followed Java in avoiding multiple inheritance (MI), which is a great leap backward from C++, in my opinion. I understand the why of avoiding virtual data members, since performance is an issue. I understand the problems of MI in C++. But the cure (using interfaces) seems worse than the disease itself. Now...
5
2180
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should multiple inheritance still be avoided? If yes, why multiple inheritance is introducted into C++?
30
2722
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
22
23383
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
47
3640
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
4930
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
6
3990
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public string UID; public string PWD; }
11
2248
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern to illustrate this. Problem: I need to expose two lists of objects from a high-level class. I would like to expose these lists as read-only, but require write access internally.
0
198
by: Scott David Daniels | last post by:
Here are some tweaks on both bits of code: Paul McGuire wrote: .... m = for b in bases: if hasattr(b, '__mro__'): if MetaHocObject.ho in b.__mro__: m.append(b) if m:
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.