
Hi all -
I just tried out the operators library for the first time today. I
was quite happy with how easily it helped me implement my test class.
Unfortunately, I'm running into some performance issues, in particular
with operator +.
The interesting thing is that the new operator += is actually faster
than my old += by about a factor of 2, but my operator + is slower
than my old + by a factor of nearly 10!
I'm new here, and not really sure how much code is appropriate to post
to the list, so here's a minimal rundown:
--------------------------------------------------------------------------
Old code:
template<typename real>
Vector3<real> operator + (const Vector3<real> &a, const Vector3<real> &b);
template<typename real>
class Vector3 {
protected:
real m_v[3];
.
.
friend Vector3 operator +<> (const Vector3 &a, const Vector3 &b);
};
template<typename real>
inline Vector3<real> operator + (const Vector3<real> &a, const
Vector3<real> &b){
Vector3<real> t;
t[0] = a[0] + b[0];
t[1] = a[1] + b[1];
t[2] = a[2] + b[2];
return t;
}
-------------------------------------------------------------------------------------------------
New code (note that the new code is templatized on size, and that my
instantiations
were of size 3 to match the above code):
template