I am seeing huge performance difference in tight loops when I do the following:
MyObject foo = bar.GetObject();
vs
MyObject* foo = bar.GetObjectPtr();
Where the specifics of the class functions are:
class MyClass
{
MyObject someobject;
MyObject& GetObject() { return someobject; }
MyObject* GetObjectPtr() { return &someobject; }
} bar;
The assignment in the first line is considerably slower than the second. Can someone explain what is going on? Does this have something to do with the default copy assignment?
If what you posted is really the code you tested, then there must be something wrong with your testing methodology, since virtually any modern compiler will generate the same code for both variants (resulting in no performance difference of any kind, of course).
If you are testing something else, then you have to provide more details about your test.