The basic test setup is a timing of the following two loops (functions explained further, but it works like a point would be expected to):
//setup vars const pointx pa( 1, 2, 3 ); const pointx pb( 4, 5, 6 ); const rtype ca = 0.17; const rtype cb = 57.3; const int loop = 2000000;
//Fast loop (0.07s)
pointx target;
for( int i=0; i < loop; i++ )
for( unsigned j=0; j < 3; j++ )
{
target[j] += pa[j];
target[j] *= ca;
target[j] -= pb[j] * cb;
}//Slow loop (0.23s)
pointx target;
for( int i=0; i < loop; i++ )
{
target += pa;
target *= ca;
target -= pb * cb; //most time here
}In the second last line of the second item I note most of the time is spent there, so I'm guessing there is a temporary created. The multiply function for a point and scalar is:
//dim is template parameter for point size
point operator*(const rtype m ) const
{
point n( *this );
for( unsigned i=0; i < dim; i++ )
n.vals[i] *= m;
return n;
}I've tried optimizing this function in every fashion, but every change just makes it slower:
-return &n
-n.vals[i] = vals[i] * m, also with
-point n; //not initializor, take advantage of NRVO
-point n( uninit ); //special ctro for no initialization
Note: pointx is simply type point<3>
The speed difference is rather extreme, and as this type of calculation is used throughout my code it can be attributed to a major slowdown in my codebase.
Any help would be appreciated.
(Compiling using GCC 3.3.1)
//extra notes
//Copy Ctor
point( const point& o )
{
for( unsigned i=0; i < dim; i++ )
vals[i] = o.vals[i];
}-- edA-qa mort-ora-y Idea Architect http://disemia.com/
-- edA-qa mort-ora-y Idea Architect http://disemia.com/ _______________________________________________ Help-gplusplus mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gplusplus
