473,226 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

c versus c++, performance wise

Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?

Signal Processing algorithms would be welcome...

Thanks

Fred
Jul 19 '05 #1
12 17259
> Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned? Signal Processing algorithms would be welcome...


As a general rule of thumb, if you write C programs and compile them with a
C++ compiler, they will run just as fast as if they were compiled with a C
compiler.

If you want to write C++ programs that cannot be expressed in an obvious way
as C programs, then it is hard to understand what kind of performance
comparisons are meaningful.
Jul 19 '05 #2
> Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?

Signal Processing algorithms would be welcome...


http://www.objectmentor.com/resource...tillUsingC.pdf

Eventually it boils down to how you use C++. Given that almost all C
code can also compile on C++ compilers, C++ can be at least as effecient
as C. C++ offeres also some features to give you the option to achieve a
better balance between elegancy, reusability and/or safety on one side
and performance on the other side. And even though some C++ features
(like virtual functions) have a run-time overhead, it is important to
realize that if you want to accomplish the same thing in C (like using
switch/case) it also has performance penalty.
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 19 '05 #3
Fred wrote:
Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?
...


Since C++ includes C as a subset (yes, there are some differences, but
they are non-essential within the context of this question), there's
absolutely no reason for any difference in "execution speed" to exist.
It doesn't.

If you are asking for a purely _statistical_ comparison, based on
performance of some existing products that implement similar
functionality in C and C++, I don't have this information. But than
again, this would be the type of statistics that can be used to prove
anything...

--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP

Jul 19 '05 #4
fr***********@sysde.eads.net (Fred) threw a soggy newspaper against the
wall, and here's what stuck:
Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?

Signal Processing algorithms would be welcome...


This might be worth a read: "Technical Report on C++ Performance"

http://anubis.dkuug.dk/jtc1/sc22/wg2...2003/n1430.pdf

PMP
Jul 19 '05 #5

"Paul M. Parks" <pa********@hNoOtSmPaAiMl.com> wrote in message news:Xn*******************************@216.168.3.4 4...
fr***********@sysde.eads.net (Fred) threw a soggy newspaper against the
wall, and here's what stuck:
Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?

Signal Processing algorithms would be welcome...


This might be worth a read: "Technical Report on C++ Performance"

http://anubis.dkuug.dk/jtc1/sc22/wg2...2003/n1430.pdf

PMP


Also :
Technical Report on C++ Performance (ISO/IEC PDTR 18015; Date: 2003-08-11; WG21 N1487=03-0070)
* http://std.dkuug.dk/JTC1/SC22/WG21/docs/PDTR18015.pdf
* http://anubis.dkuug.dk/jtc1/sc22/wg2...2003/n1487.pdf
--
=====================================
Alex Vinokur
mailto:al****@connect.to
http://mathforum.org/library/view/10978.html
news://news.gmane.org/gmane.comp.lang.c++.perfometer
=====================================

Jul 19 '05 #6

"Fred" <fr***********@sysde.eads.net> wrote in message news:33*************************@posting.google.co m...
Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?

Signal Processing algorithms would be welcome...

Thanks

Fred


Look at :
http://groups.google.com/groups?selm...news.dfncis.de
http://news.gmane.org/gmane.comp.lang.c++.perfometer/
news://news.gmane.org/gmane.comp.lang.c++.perfometer

http://www.eventhelix.com/RealtimeMa...erformance.htm
http://www.eventhelix.com/RealtimeMa...rformance2.htm
http://www.eventhelix.com/RealtimeMa...AndCPPCode.htm

--
=====================================
Alex Vinokur
mailto:al****@connect.to
http://mathforum.org/library/view/10978.html
=====================================

Jul 19 '05 #7
"Alex Vinokur" <al****@bigfoot.com> threw a soggy newspaper against the
wall, and here's what stuck:
"Paul M. Parks" <pa********@hNoOtSmPaAiMl.com> wrote in message
news:Xn*******************************@216.168.3.4 4...

This might be worth a read: "Technical Report on C++ Performance"


Also :
Technical Report on C++ Performance (ISO/IEC PDTR 18015; Date:
2003-08-11; WG21 N1487=03-0070) *
http://std.dkuug.dk/JTC1/SC22/WG21/docs/PDTR18015.pdf *
http://anubis.dkuug.dk/jtc1/sc22/wg2...2003/n1487.pdf


Oops. Thanks for clearing that up.

PMP
Jul 19 '05 #8
Fred wrote:
Has anyone a link or any information comparing C and C++
as far as execution speed is concerned?

Signal Processing algorithms would be welcome...

Take a look at the
Vector Signal and Image Processing Library (VSIPL) web page:

http://www.vsipl.org/

and the
High Performance Embedded Computing Software Initiative (HPEC-SI)
web page:

http://www.hpec-si.org/

They specify *standard* APIs for DSP libraries
which should permit you to compare implementations
from competing vendors and, eventually, to compare implementations
for both C and C++ language bindings.
Some vendors may actually use C++ compilers to compile their C codes.

Jul 19 '05 #9
In article <33*************************@posting.google.com> ,
fr***********@sysde.eads.net (Fred) wrote:
Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?


A lot depends on how you write your C++ code.

As a baseline, you could write your program just like you would in C but
compile it with a C++ compiler. The performance of C vs. C++ is a wash
here. Of course this may sound obvbious, but I think it is an important
point because in most systems, performance is only an issue for a subset
of the code. With C++ you can always fall back to C-style programming
in areas where your program needs the performance and where C++ style
code would lead to an unacceptable performance penalty.

For example, the iostream library provides a lot more power than stdio,
but it also tends to run slower. If this isn't critical to your system
performance, then iostream is worth learning/using. However I wrote one
program where logging was a significant part of the overall system
performance and using iostream was about 3x slower than fprintf(), so I
wound up using fprintf(). The decision to write the program in C++ was
still a good one since I benefited from many of the C++ mechanisms
throughout the rest of the program and only had to fall back to a more
"C-like" approach in this one instance.

C++ has quite a few features (const, inline functions, templates) that
afford better abstraction than C, but when used properly, result in no
performance penalty.

There are a few instances (exceptions, virtual functions) where the
resulting code is usually more efficient than what you would've written
yourself in C - provided you needed the functionality. For example,
exceptions are often more efficient than explicit error checking, but if
your C program wasn't going to check errors, then exceptions aren't
helping you. Same with virtual functions versus switch statements or
explicit function pointers.

With the complexity and power of C++ comes a lot of potential for
problems - especially performance wise. This can be a real concern for
a performance sensitive project staffed by people who are solid C
programmers but new to C++. My only advice would be to go ahead and use
C++, but be disciplined in what features you use. Don't make everything
a virtual function and create a deep object hierarchy just because you
can in C++. It would also be worth reading up on some common pitfalls
and optimizations for C++ ("Effective C++" by Meyers is an excellent
book on the subject).

Dave Baum
Jul 19 '05 #10
Fred wrote:
Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?

Signal Processing algorithms would be welcome...


We do a lot of mathematical computations, and some of our
original computational algorithms, solvers, etc were written
in fortran 20-30 years, when we converted them to C++ and
compared the old with the new we recorded negligible (2%)
performance degradation.

Jul 19 '05 #11
Fred wrote:
Has anyone a link or any information comparing c and c++ as far as
execution speed is concerned?


Under linux, compile the same source (e.g. Hello World) as C and C++. You
will notice that the C executable runs slightly faster. This happens
because the C version is linked only against libc, whereas the C++ version
is linked against libc, libstdc++, libgcc_s and libm. So there exists a
slight (almost constant, you can verify that by ) performance penalty, due
to increased *loading* time. At *run* time, there is no observable
difference. You can verify it by running a large loop.

Not that this only happens with dynamic executables. Static executables
don't seem to have any difference whatsoever.

Jul 19 '05 #12
The following articles compare C and C++ performance by comparing the
C++ code with equivalent C code.

http://www.eventhelix.com/RealtimeMa...erformance.htm

http://www.eventhelix.com/RealtimeMa...rformance2.htm

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - System Architecture Design CASE Tool
Jul 19 '05 #13

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

Similar topics

4
by: Matt Garman | last post by:
Is there any difference, performance-wise, accessing elements of a vector using iterators or the subscript operator? In other words, say I have a vector of strings: vector<string> strvec; ...
11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
0
by: Bigal | last post by:
If I want to create a ListBox filled by a database query, it is not recommended to enable the viewstate of the form, because it does not make sense to reconstruct the whole and costs performance....
8
by: Gary Wessle | last post by:
Hi while I am reading this C++ book, I noticed the iterator is being used to loop through a container, say a vector. I am used to use "for(int=0;i<vec.size();++i)" which is better to use? ...
4
by: RS | last post by:
Hi all, I was told that using unsigned int instead of int can speed up the code. Is this true? If so, why? Are there are any other rules one should follow to optimize the code for speed (i.e....
8
patjones
by: patjones | last post by:
Hi all - This is really more of a strategic question rather than a specific debugging question, though I guess you could say it's a little of both. I've got a database which I completely...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.