Is it a simple getter? or is it calculating every time?
If I have a for loop like this:
for (int i = 0; i < myVector.size(); i++) { }
where I only need to use the size once, would it be better to calculate this once before the loop and store it in a variable? Or is size() just a simple getter and it would make little difference?
That is implementation defined. Assuming that implementations want to provide efficient standard libraries, the two most probable implementations are:
In any case the standard requires the complexity to be constant, and you should not really worry about it. Also compilers often optimize enough to make no difference to storing your size on your own.