[Insight-developers] Iterator VS IteratorWithIndex Speed

Luis Ibanez luis.ibanez@kitware.com
Sun, 11 May 2003 15:16:13 -0400


Hi Stephen,

Yeap the last time I looked at this test closely
the conclusion was that the Iterator with index
is slower if you only want to go through the data
with it.Get() and it.Set(). But, it is faster if
you also need to perform it.GetIndex().

The basic difference between the Iterator and the
IteratorWithIndex is that the IteratorWithIndex
continuously update its internal index. This
result in a computational overhead. The overhead
pays off if you consult the index during the
iteratons, otherwise it is just... overhead.

The normal iterators do not update any internal index,
so, if you ask for the index, it has to recomputed
through a time expensive method.

So, the recommendation is in general, to use
ImageRegionIterator if you only plan to do Set()/Get(),
and to use ImageRegionIteratorWithIndex if you plan to
call GetIndex().


    Luis


-------------------------------
Stephen R. Aylward wrote:
> 
> Hi,
> 
> It ends up that Luis already had also written an 
> iterator/iteratorWithIndex speed test.
> 
> Data: 390x390x390 region of an unsigned short image
> 
> memset
>     Single Processor: 0.28
>     Dual Processor:   0.25
> scan using memory pointer in a 1D loop
>     Single Processor: 0
>     Dual Processor:   0
> scan using memory pointer in 3 nested loops
>     Single Processor: 0.18
>     Dual Processor:   0.16
> scan using iterator
>     Single Processor: 0.36
>     Dual Processor:   0.25
> scan using iteratorWithIndex
>     Single Processor: 1.15
>     Dual Processor:   0.73
> 
> So, IteratorWithIndex is about 4x slower than the Iterator without an 
> index.  HOWEVER, some of the difference is reduced with multi-processors 
> (maintaining the index must parallelize well?).   On a dual processor 
> machine the difference between iteratorWithIndex and Iterator is reduced 
> to 3x.
> 
> Stephen