[Insight-developers] itkVector: specialization and performance

Luis Ibanez ibanez@cs.unc.edu
Sun, 7 Jan 2001 20:40:43 -0500 (EST)


Looking closer to the implementation
of itkVector, we can verify that 
the use of a for loop in the basic 
arithmetic methods, introduces an 
overload in computation time. 

This is more notorious in lower dimensions
(e.g. 2D, 3D).  One option to improve the
performace is to specialize these methods
for the low dimensional cases (the kind
of approach used in Blitz++).

----

in the version of itkVector defined at:
http://www.cs.unc.edu/~ibanez/Insight/Code/Geometry/itkVector.txx

there are two specialized methods for adding vectors 
in the 2D and 3D case.

The tables below show the relative perfomaces when specialization
is used, depending on the fact of compiling for debugging -g
or with optimization -O2.  All the times have been evaluated
with 'time' unix command, for 10000000 vector add operations.

-----------------------------------------------
Vector<double,2>    // 2D case
-----------------------------------------------
            |  Debug (-g) | Optimization (-O2) 
-----------------------------------------------
default     |    4.61     |         2.96      |
-----------------------------------------------
specialized |    2.18     |         2.42**    |
-----------------------------------------------


-----------------------------------------------
Vector<double,3>    // 3D case
-----------------------------------------------
            |  Debug (-g) | Optimization (-O2) 
-----------------------------------------------
default     |    6.08     |         4.02      |
-----------------------------------------------
specialized |    2.54     |         3.23      |
-----------------------------------------------

**(the specialized version is slower 
   with optimization !?)

-------

So,
the question is if this difference in performance
justify the effort to writte and maintain the 
specialized versions of the vector arithmetic
methods  for lower dimension.


any comments ?



Luis