Re: [Boost-users] [operators] loss of performance
At 23:05 2006-05-07, you wrote:
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
class vec : boost::additive< vec , boost::multiplicative< vec , T > > { private: typedef unsigned int uint; typedef const T &const_reference; typedef T &reference; private: boost::array
m_v; template<typename U> vec &operator += (const vec &t){ for(uint i = 0; i < S; ++i){ m_v[i] += t.m_v[i]; } return *this; } };
Any ideas how to increase the performance of the new code here? A factor of 10 makes it seem like I am just missing something important.
you showed us the code that you claim is faster, what do you want us to do?
Thanks, Brian _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
I'm essentially interested in the functionality of the operators
library, and mostly curious if I'm using it in a less than optimal way
(ie. I need to #define something, or write my operator += in a
different way).
Is it possible that the old code is being autovectorized, while for
some reason the new code can't be?
I'm using gcc 4.1 on a linux system.
Thanks,
Brian
On 5/8/06, Victor A. Wagner Jr.
At 23:05 2006-05-07, you wrote:
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
class vec : boost::additive< vec , boost::multiplicative< vec , T > > { private: typedef unsigned int uint; typedef const T &const_reference; typedef T &reference; private: boost::array
m_v; template<typename U> vec &operator += (const vec &t){ for(uint i = 0; i < S; ++i){ m_v[i] += t.m_v[i]; } return *this; } };
Any ideas how to increase the performance of the new code here? A factor of 10 makes it seem like I am just missing something important.
you showed us the code that you claim is faster, what do you want us to do?
Thanks, Brian _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Brian Budge
-
Victor A. Wagner Jr.