[Insight-developers] fill

Bradley Lowekamp blowekamp at mail.nih.gov
Wed Apr 10 08:47:04 EDT 2013


Marius,

Sound like a great idea! Those are some great looking numbers. Also keep in mind that I got rather difference performance for different types with fill.

Using std::copy, and std::fill are both good things. Keep an eye out for usage of std::copy too, that can have even bigger change in performance.

Brad

On Apr 10, 2013, at 8:26 AM, <M.Staring at lumc.nl> wrote:

> Hi Brad,
>  
> I saw your gerrit topic http://review.source.kitware.com/#/c/10762/
> And I wondered whether such a change would have implications elsewhere in the toolkit, most notably the image registration framework where array.Fill(0) is used quite a lot for initialization of derivatives and transform parameters.
>  
> So, I did a test, see the attached code, to compare an itk.Fill with a standard C fill using a for loop, with a C++ fill using std::fill_n. The results are in favour of the C++ way, for a tested array size between 1e2 and 1e7.
>  
> On my Win7 64bit machine using VS2008:
>  
> Array size = 100, repetitions = 20000000
> The elapsed time for a itk.Fill   2483 ms.
> The elapsed time for a C   fill   4748 ms.
> The elapsed time for a C++ fill_n 543 ms.
>  
> Array size = 1000, repetitions = 2000000
> The elapsed time for a itk.Fill   2418 ms.
> The elapsed time for a C   fill   4585 ms.
> The elapsed time for a C++ fill_n 404 ms.
>  
> Array size = 10000, repetitions = 200000
> The elapsed time for a itk.Fill   2534 ms.
> The elapsed time for a C   fill   4605 ms.
> The elapsed time for a C++ fill_n 618 ms.
>  
> Array size = 100000, repetitions = 20000
> The elapsed time for a itk.Fill   2553 ms.
> The elapsed time for a C   fill   4593 ms.
> The elapsed time for a C++ fill_n 580 ms.
>  
> Array size = 1000000, repetitions = 2000
> The elapsed time for a itk.Fill   2605 ms.
> The elapsed time for a C   fill   4665 ms.
> The elapsed time for a C++ fill_n 1284 ms.
>  
> Array size = 10000000, repetitions = 200
> The elapsed time for a itk.Fill   3289 ms.
> The elapsed time for a C   fill   4780 ms.
> The elapsed time for a C++ fill_n 1168 ms.
>  
> ---
> On my linux Ubuntu with gcc 4.6.3:
>  
> Array size = 100, repetitions = 20000000
> The elapsed time for a itk.Fill   1870000 ms.
> The elapsed time for a C   fill   1660000 ms.
> The elapsed time for a C++ fill_n 490000 ms.
>  
> Array size = 1000, repetitions = 2000000
> The elapsed time for a itk.Fill   1520000 ms.
> The elapsed time for a C   fill   1520000 ms.
> The elapsed time for a C++ fill_n 390000 ms.
>  
> Array size = 10000, repetitions = 200000
> The elapsed time for a itk.Fill   1510000 ms.
> The elapsed time for a C   fill   1500000 ms.
> The elapsed time for a C++ fill_n 380000 ms.
>  
> Array size = 100000, repetitions = 20000
> The elapsed time for a itk.Fill   1500000 ms.
> The elapsed time for a C   fill   1500000 ms.
> The elapsed time for a C++ fill_n 440000 ms.
>  
> Array size = 1000000, repetitions = 2000
> The elapsed time for a itk.Fill   1500000 ms.
> The elapsed time for a C   fill   1500000 ms.
> The elapsed time for a C++ fill_n 510000 ms.
>  
> Array size = 10000000, repetitions = 200
> The elapsed time for a itk.Fill   1530000 ms.
> The elapsed time for a C   fill   1520000 ms.
> The elapsed time for a C++ fill_n 1100000 ms.
>  
>  
> I did not further test this on the effect on registration, but changing the itk::Array::Fill function to use std::fill_n may be a nice idea.
> What do you think?
>  
> Marius
>  
> Marius Staring, PhD
> Division of Image Processing (LKEB)
> Department of Radiology
> Leiden University Medical Center
> PO Box 9600, 2300 RC Leiden, The Netherlands
> phone: +31 (0)71 526 2137, fax: +31 (0)71 524 8256
> m.staring at lumc.nl
>  
> <CMakeLists.txt><test.cxx>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20130410/bb35ef19/attachment.htm>


More information about the Insight-developers mailing list