How much faster is C compared to C++?

Started by
9 comments, last by Qw3r7yU10p! 19 years, 6 months ago
Hi, I was wondering if anyone knew averagely, how much faster C is, compared to C++. Thanks
Advertisement
Exactly the same.

Most of today's C compiler really are C++ compilers. The parser may different, but the code generating engine remains the same.

If you were to implement, by hand, C++-equivalent constructs in C (e.g. polymorphism...) you would probably end up with a slower and kludgier solution.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
All things being equal, they should compile into pretty much the same instructions, hence the same speed.

Realistically, you should use whatever you create more maintainable, bug-free, and elegant code, as missing those will influence the speed of your program by orders of magnitude more than the speed difference between C and C++
Just one more quick question, so C doesnt have classes but has structures?

And anyone know where I can find some OpenGl tutorials written in C?

Thanks

Quote:Original post by johnnyBravo
Just one more quick question, so C doesnt have classes but has structures?


C has struct and union, as well as enum.

Quote:And anyone know where I can find some OpenGl tutorials written in C?


Nehe Tutorials on Gamedev.net
OpenGL.Org/
and in the Red Book (online)

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by johnnyBravo
Hi, I was wondering if anyone knew averagely, how much faster C is, compared to C++.


C is slower than C++
Quote:Original post by petewood
Quote:Original post by johnnyBravo
Hi, I was wondering if anyone knew averagely, how much faster C is, compared to C++.


C is slower than C++

and C is still slower than assembly!
if you want a realworld/game context example checkout the quake .net port:
How is the performance of the managed version?
Initially, the managed version was faster than the native version when the default processor optimization setting /G5 (Pentium) was used. Changing the optimization setting to /G7 (Pentium 4 and Above) created a native version that runs around 15% faster then the managed version.


Note, the assembly code was disabled for the native and managed versions so both versions are slower than the original Quake version
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Quote:Original post by petewood
Quote:Original post by johnnyBravo
Hi, I was wondering if anyone knew averagely, how much faster C is, compared to C++.


C is slower than C++
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Quote:Original post by petewood
Quote:Original post by johnnyBravo
Hi, I was wondering if anyone knew averagely, how much faster C is, compared to C++.


C is slower than C++


Really what do you base that on? I'd really like to know just pulled it out of your arse or?

Anyway from my experience with gcc/g++ c++ seems to have a slightly higher memory usage than c, and is also slightly slower when you fully utilize such features as polymorphism etc. When using linux you could use the icc compiler tho since it briungs the c++ up to pretty much the same speed as c code. It really depends on what compiler you use, g++ has had some issues and hopefully they will be/are solved ;) Until then I'm gonna stick to C(gcc) for time critical low level stuff. I doubt you are using linux tho so just go with whatever feels right.

Note: all of the above is MHO so don't get too excited.

- Damage Incorporated.
c speed==c++ speed

The only way c++ would be slower is if you use things like polymorphism. And that is not due to the language but the design. If you design your program right however using polymorphism (etc.) the speed diffrence is very very marginal.
______________________________________________________________________________________With the flesh of a cow.

This topic is closed to new replies.

Advertisement