Time and memory performance of C versus C++

  • Thread starter Generic Usenet Account
  • Start date
D

Duane Hebert

red floyd said:
To quote Pauli.... This isn't right. It isn't even wrong.

Lets see.... avionics, video codec, audio codec, other multimedia, printer
engine....

Yeah, those are just turning on a few lights.

Some of the lights are gigantic furnaces filled with
dnh3 and h2 at extremely high temperatures.
 
A

acehreli

These days with 3ghz computers with more than 1 gbyte RAM what is so
important about elegant, efficient code?

Efficient code has more than one meaning:

1) If you mean fast program produced from that "efficient code," those
fast computers don't help at all with this simple problem: user
interfaces are not responsive. I click, nothing happens... I select a
pull-down menu, it is empty for a while. No matter how fast your
computer is.

2) If you mean code that is easy to maintain and alter, then I
completely disagree with you that fast computers can help. If there
are 14 files to modify to add one property to some component, then
your code is inefficient no matter what.

3) Some other meaning?

Ali
 
I

Ivar Rosquist

Malcolm McLean wrote:


To quote Pauli.... This isn't right. It isn't even wrong.

Lets see.... avionics, video codec, audio codec, other multimedia,
printer engine....

Yeah, those are just turning on a few lights.

Well, what can you expect from McLean, one who is so incompetent
that he does not know that he does not know?
 
J

James Kuyper

....
Jeez, I just brought it up as a topic for discussion, didn't mean for
anyone to get nasty

You're getting a nasty response because a lot of us have been victims of
programmers who felt exactly the same way you do. We use applications
that run too slow and take up too much memory, for no particularly good
reason, just because somebody thought there was no point to worrying
about efficiency. We update programs written by other people that are
maintenance nightmares because the original author thought that there
was no importance to writing code elegantly.
 
M

Malcolm McLean

Juha Nieminen said:
Ever played a modern computer game with millions of polygons per
level, even tens of thousands of polygons visible at the same time,
complex physics, etc? Do you want to play that kind of game at 0.5
frames per second or at 30 frames per second in your 3GHz computer?
That rate-limiting step in such a game is probably the rasteriser rather
than the main processor.
 
M

Malcolm McLean

red floyd said:
To quote Pauli.... This isn't right. It isn't even wrong.

Lets see.... avionics, video codec, audio codec, other multimedia, printer
engine....

Yeah, those are just turning on a few lights.
"Typically" means there will be a few counter-examples.
 
F

Flash Gordon

Malcolm McLean wrote, On 10/11/07 08:58:
"Typically" means there will be a few counter-examples.

Those "few counter-example" include within sight of me at least 7
embedded processors, the GPS I use in my car, and a minimum of one other
processor in my car. In fact, it will include at least one processor in
every DVD player, digital TV, DTV receiver, satalite decoder, cable TV
decoder, GPS, car and computer being sold as well as a lot of other kit.
Yes, computers *do* have embedded processors in them. I think you will
be hard pressed to find a household in the UK without a few of those
items. So this is NOT a small number of counter-examples, rather it is
several large industries.
 
L

lovecreatesbea...

A lot of research has been done to prove that the contention that C
code is more efficient and more compact than equivalent C++ code is a
myth.

C++ is slower than C for the first one may call three functions:
cpp.constructor(), cpp.function() and cpp.destructor(). If it doesn't
call the constructor and destructor, it's C.
 
C

cr88192

Malcolm McLean said:
That rate-limiting step in such a game is probably the rasteriser rather
than the main processor.

maybe if the game is heavily loaded with shaders...

but, at least for fairly basic rendering (no shaders, no stenciling, ...), I
suspect it is actually the case that a lot more often ends up going into
stuff going on in the main processor, than in the video card itself.

it may not seem like it, but the main engine has a hard time keeping up,
even when doing bunches of vertex-level calculations.

the speed of the graphics card should not be so easily discounted.

(of course, use shaders or enable stenciling, and the thing typically slows
way down...).

 
M

Malcolm McLean

Ian Collins said:
I bet there's more cell phones shipped a year than washing machines.
Little 8-bit embedded processors outsell others by a wide margin.

I'd agree, however, the market is changing. Digital tellies and mobile
phones are getting so sophisticated that they are blurring the line between
embedded devices and computers in their own right. We shouldn't fear for our
jobs.
 
P

Pete Becker

C++ is slower than C for the first one may call three functions:
cpp.constructor(), cpp.function() and cpp.destructor(). If it doesn't
call the constructor and destructor, it's C.

If an object needs to manage resources, then it needs to manage
resources. In C++ that's what the constructor and destructor do. In C
that's done explicitly by calling init and cleanup functions. Either
way, the speed of correct code is in large part determined by what has
to be done, not by the language that's being used to do it.
 
E

EventHelix.com

A lot of research has been done to prove that the contention that C
code is more efficient and more compact than equivalent C++ code is a
myth. My posting pertains to a slightly different aspect of this
debate. Here are my two questions:

1) Does anyone have any information on comparison of C and C++
software written for the ARM processor?

2) Are there any compiler and CPU dependencies that have to be
factored in while debating this issue? Or, is the issue more or less
settled for all compilers and all CPUs?

Thanks,
Kandregula Anil K.

The following links map C++ code to it's equivalent C. This will let
you judge the performance impact of C++.

http://www.eventhelix.com/RealtimeMantra/Basics/ComparingCPPAndCPerformance.htm

http://www.eventhelix.com/RealtimeMantra/Basics/ComparingCPPAndCPerformance2.htm
 
F

Flash Gordon

Malcolm McLean wrote, On 10/11/07 10:07:
Little 8-bit embedded processors outsell others by a wide margin.

The little 8-bit processors are often doing a heck of a lot more than
turning on a few lights. One of those little 8-bit processors that I
know about is doing a lot of trig, another I know about is doing massive
amounts of comms processing and so on.
I'd agree, however, the market is changing. Digital tellies and mobile
phones are getting so sophisticated that they are blurring the line
between embedded devices and computers in their own right.

Mobile phones and PDAs act like computers, but the TVs, cars, set to
boxes etc are all definitely embedded devices.
We shouldn't
fear for our jobs.

No one has said they do.
 
T

Tim H

Those "few counter-example" include within sight of me at least 7
embedded processors, the GPS I use in my car, and a minimum of one other
processor in my car. In fact, it will include at least one processor in
every DVD player, digital TV, DTV receiver, satalite decoder, cable TV
decoder, GPS, car and computer being sold as well as a lot of other kit.
Yes, computers *do* have embedded processors in them. I think you will
be hard pressed to find a household in the UK without a few of those
items. So this is NOT a small number of counter-examples, rather it is
several large industries.

Don't forget your computer keyboard, your optical mouse, very likely
your wristwatch, your microwave, your stove, your refrigerator, and
basically most anything that has electronics these days.

There are more ARM processors deployed in the world than any other
CPU.

Tim
 
I

Ian Collins

EventHelix.com said:
The following links map C++ code to it's equivalent C. This will let
you judge the performance impact of C++.

http://www.eventhelix.com/RealtimeMantra/Basics/ComparingCPPAndCPerformance.htm
The concluding statement concerning static member functions "Thus they
are accessed without indirection of the object. This can be useful in
defining methods which need C level function call conventions." is wrong.

Static member functions a not C functions, they have C++ linkage. The
only correct technique for providing a C linkage function from C++ is to
use a function declares as extern "C".
Your sig is missing the space after the '--'.
 
M

Malcolm McLean

Pete Becker said:
If an object needs to manage resources, then it needs to manage resources.
In C++ that's what the constructor and destructor do. In C that's done
explicitly by calling init and cleanup functions. Either way, the speed of
correct code is in large part determined by what has to be done, not by
the language that's being used to do it.
But object-oriented languages often throw away cycles for the convenience of
the programmer. For instance frequently you know from the program logic that
an array bounds error cannot happen. However many languages will check each
access anyway. Since the vast majority of code is not in the inner loop, and
thus not time critical, that's often a reasonable trade off. But not always.
 
M

Malcolm McLean

Flash Gordon said:
Malcolm McLean wrote, On 10/11/07 10:07:

The little 8-bit processors are often doing a heck of a lot more than
turning on a few lights. One of those little 8-bit processors that I know
about is doing a lot of trig, another I know about is doing massive
amounts of comms processing and so on.

Mobile phones and PDAs act like computers, but the TVs, cars, set to boxes
etc are all definitely embedded devices.
For every glamorous processor doing frequency transforms to run an MPEG
codec or something there are probably several doing humble jobs.
 
I

Ian Collins

Malcolm said:
But object-oriented languages often throw away cycles for the
convenience of the programmer. For instance frequently you know from the
program logic that an array bounds error cannot happen. However many
languages will check each access anyway. Since the vast majority of code
is not in the inner loop, and thus not time critical, that's often a
reasonable trade off. But not always.
What does any of the above have to do with OO? The first language I
used that uses automatic array bounds checking was Pascal. C++, even
when used for OO programming, does not perform array bounds checking.
 
M

Malcolm McLean

Ian Collins said:
What does any of the above have to do with OO? The first language I
used that uses automatic array bounds checking was Pascal. C++, even
when used for OO programming, does not perform array bounds checking.
If you treat arays as "objects" it becomes natural for an access to cause
code to be executed. C++ even allows overloading of the subscript operator
to permit this. You can have bounds checking in non-OO languages, but it
implies special compiler tricks and / or hidden variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top