"Premature optimization is the root of all evil"
I think this we can all agree upon. And I try very hard to avoid doing that.
But recently I have been wondering about the practice of passing parameters by const Reference instead of by Value. I have been taught / learned read i that non-trivial function arguments (i.e. most non-primitive types) should preferably be passed by const reference - quite a few books I've read recommend this as a "best practice".
Still I cannot help but wonder: Modern compilers and new language features can work wonders, so the knowledge I have learned may very well be outdated, and I never actually bothered to profile if there are any performance differences between
void fooByValue(SomeDataStruct data);
and
void fooByReference(const SomeDataStruct& data);
Is the practice ofthat I have learned - passing const references that I have learned(by default for non-trivial types) - premature optimization?