How much does using the dot operator to access some data cost speed-wise? Eg:
struct A{
public:
A(): a(0){};
int a;
};
int main(){
A obj;
int b = 0;
cout << obj.a; // How much slower is this
cout << b; // Than this...?
return 0;
}
I know I should benchmark, but are there any general understandings here?
Let’s take a look at dissasembled code:
This was compiled without optimizations. And even so, they take the same time.
With optimizations, the code is shorter, but still remains largely the same:
So for your snippet, the performance is identical. Small differences might occur on different compilers, but the overhead will always be negligible or 0.