[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc
Subject:    RE: Overhead in C and C++
From:       "Paul Koning" <Paul_Koning () Dell ! com>
Date:       2010-02-25 14:49:30
Message-ID: D8CEBB6AE9D43848BD2220619A43F32653888E () M31 ! equallogic ! com
[Download RAW message or body]

> i'm working on the topic "overhead and codesize in C and C++".  The
> goal of this work is to find out, why C++ is not as fast as normal C
> code (in same application).

Why do you believe this is true?

> But already by the beginning we found out something very interesting.
> 
> The Code:
> int main(int argc, char *argv[])
> {
> return 0;
> }
> No function so far. But this compiled with gcc and g++ (on Linux
> Redhead EL5, Intel Xeon 5130 (x86_64))
> 
> Codesize in C:    7820
> Codesize in C++: 8175
> 
> But much more interesting is the number of instructions (mesured with
> callgrind/kcachegrind):
> For main:
> Ir in C: 7
> Ir in C++: 7

Well, of course.

> Whole program (you see, there is no include)
> Ir in C: 80 158 (a lot)
> Ir in C++: 1 295 980 (massive!!)

So?  You started out asking about performance.  Code size is a completely independent \
property.  Since the semantics of C++ are more complex than those of C (due to things \
like constructors, exceptions, etc.) it is to be expected that a complete program is \
slightly larger.  That doesn't mean it is slower.

Note also that a valid comparison is between C++ and equivalent C.  For example, a \
comparison between regular function calls in C and virtual method calls in C++ is \
invalid.  A comparison between virtual method calls in C++ and calls through a table \
of function pointers in C is valid -- and will produce the same performance since you \
are in fact doing the same thing.

	paul


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic