mi**************@gmail.com wrote:
BBox::Expand(float delta){
Vector d = Vector(delta, delta, delta);
p_min -= d;
p_max += d;
}
BBox::Expand(float delta){
p_min -= Vector(delta, delta, delta);
p_max += Vector(delta, delta, delta);
}
Logically the first method would only make 1 Vector object and the
second 2, so method two would take more cpu instructions? Or does c++
do some intern stuff to optimise this?
It's really easy to measure this sort of thing: write the code (looks
like you've already done it), add a simple main() that calls it a few
zillion times, compile with all available optimisations enabled, and
measure execution time. That will give you a more accurate answer for
your compiler and hardware than all the people here can offer, and it's
quicker.
FWIW, my guess is that as long as the caller can see Vector's
constructor and BBox::Expand and the rest inline, then you'll get
essentially optimal code from both.
If you're coding for an x86 system and performance is vital, then you
may like to investigate using SIMD instructions for this sort of thing,
i.e. processing the x, y and z components in parallel. How to do that
is off-topic for this group, but it's likely to make more impact than
tweaking the details of the C++ coding style.
Phil.