[Insight-developers] Empty FixedArray destructor: Performance hit using gcc (times 2)

Gert Wollny gert at die.upm.es
Thu Jun 5 10:19:43 EDT 2008


> Here is a suggested skeleton for the test:
> 
> ---------------------------------------------
> #include "itkFixedArray.h"
> #include "itkTimeProbesCollectorBase.h"
> 
> int main()
> {
> 
> typedef itk::FixedArray< double, 2 >   ArrayType;
> 
> ArrayType foo[10];
> ArrayType * p = foo;
> ArrayType * q = foo;
> p++;
> 
> char * cp = (char*)( p );
> char * cq = (char*)( q );
> 
> std::cout << "Type size  =" << sizeof( ArrayType ) << std::endl;
> std::cout << "Pointer step = " << int( cp - cq ) << std::endl;
> 
> itk::TimeProbesCollectorBase chronometer;
> 
> chronometer.Start("FixedArray");
> for(unsigned long t=0; t<1000000L; t++)
>    {
>    ArrayType foo;
>    foo[0] = t;
>    }
> chronometer.Stop("FixedArray");
> 
> chronometer.Report(std::cout);
> 
> return 0;
> }
> 
> ---------------------------------------------
> 
I've did a test with g++  4.2.3 (Ubuntu)
using compile flags "-g -O2". If the destructor is implemented, it is called (of course), 
if there is no explicit implementation of the destructor, the call to the destructor is optimized away resulting in a ~30% speedup of above loop. 
In both cases alignment is 16.

Best

Gert




More information about the Insight-developers mailing list