Comparative performance of C(gcc) and C++(g++)

Alexander Helm helm@fs.tum.de
Thu Jan 30 17:11:00 GMT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

As most people here on the list already told you:

	It depends!

It depends on the problem domain and it depends on the concepts of C++
you want to use (templates, virtual functions, object inheritance, ...).

Some problems are addicted to C++ because the problem domain can use
many of the advantages of C++. Other problems can't really exploit the
advanteges of C++ and may be happier if you implement them in C because
incautios usage of C++ may be a big risk.

There is no general answer to your question, at least because you can
nearly program C using a C++ Compiler.

If you use GNU compilers the differences are mostly dependend on the
different features of the language, because AFAIK every GNU compiler
frontend translates to an intermediate code. This intermediate code than
is optimized by the compiler backend (completely independent of the
previously used language).

If you need every bit of performance use assembler. Mostly handcrafted
code is faster than produced code. (not much, but it may be around the
3-5% you were talking about.)

And a last tip: Start coding, profile your code, look where the time
gets lost, optimize only this part AND try to build a C and C++ program
for a small subdomain of your problem and look which is better for your
needs.

	HTH
	Alexander

Ivan Vieira Velho wrote:
| Hi,
| My problem is decide witch language use in an project that analysis
| demonstred complex , huge and need a better use of all resources  in
| the machine (highly optimized).
| The choose for Assembly was abandoned because C/C++ compilers support
| assembler and have highly optimized functions and tools. For an
| specific implementation major C/C++ compilers support inline assembler.
| Well, the last choose is the project implementation language (C or
| C++).
| For me 3-5% more eficiency (speed and memory) for C is remarkable, 1-2%
| more, I will choose C++ .
| This is my problem.
|
| _______________________________________________________________________
| Busca Yahoo!
| O serviço de busca mais completo da Internet. O que você pensar o
Yahoo! encontra.
| http://br.busca.yahoo.com/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+OVy+dcrm1qkhaakRAv+IAKCL0BpUsP0X22HS+IJ56XDfw3CcngCcDZqS
vrgWIidCkITjLE/sUxfJ8F8=
=ub3L
-----END PGP SIGNATURE-----



More information about the Gcc-help mailing list