c++

B

Bo Persson

(e-mail address removed) wrote:
:: If you have this:
::
:: int c;
::
:: Which is faster?
::
:: a. c = c + 1;
::
:: b. c++;

No difference.
 
J

jkherciueh

If you have this:

int c;

Which is faster?

a. c = c + 1;

b. c++;

Depends on hardware, compiler, compiler settings and options, and possibly
the day of the week. Your only option to get a reliable answer is to
measure. That said, chances are that your compiler will generate identical
object code for both statements.


Best

Kai-Uwe Bux
 
J

James Kanze

None. Without a doubt, it's

Sorry Victor, but that's false. Every compiler I've ever used
generates exactly the same code for all three.

More generally, the answer to almost any question "which is
faster" is: it depends on the compiler. You have to set up a
test harness and measure. (In particular: despite claims by
some prominent "experts", I've yet to find a case where there
was a measurable difference between c++ and ++c, regardless of
the type of c. I can easily create cases where ++c would be
significantly faster, but they don't seem to actually occur in
real life.)
 

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

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top