+8  A: 

const correctness is a good thing with respect to maintainability. Otherwise, clients of your class could break that class's internal members. For instance, consider the standard std::string::c_str() -- if it couldn't return a const value, you'd be able to screw around with the internal buffer of the string!

That said, any compiler worth it's salt is going to be able to detect if a variable is really constant or not, and apply correct optimizations. Don't use const for performance reasons. Use it for maintainability reasons.

Billy ONeal
"you'd be able to screw around with the internal buffer of the string!" - crucially, you'd be able to *accidentally* screw around with the internal buffer. Compiler errors due to `const` are signposts, saying, "you're doing something stupid".
Steve Jessop
@Steve: Good point. +1 to comment.
Billy ONeal
... and const-casts are signposts saying, "the author of this code is trying to do something clever" ;-)
Steve Jessop
@Steve Jessop - or const-cast are signposts saying "I'm trying to bolt up a const-correct bunch of code to a non-const-correct one, and I can't fix either one". Which, let me tell you, is in no way clever, just annoying.
Michael Kohne
@Michael - yes, fair point. Perhaps the original signpost isn't "you're doing something stupid", rather "someone's doing something stupid".
Steve Jessop
+1  A: 

in my experience, no

For scalar variables, compiler is able to determine whenever the value is changed and perform necessary optimization itself.

For array pointers, const correctness is no guarantee that values are really constant in presence of potential aliasing problems. Hence compiler can not use const modifier alone to perform optimizations

if you are looking optimization, you should consider __restrict__ or special function modifiers/attributes: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

aaa
+1  A: 

A bit old, but still applies: http://www.gotw.ca/gotw/081.htm And some more: http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/

Maxim Yegorushkin