Skip to content

Conversation

@blowekamp
Copy link
Member

No description provided.

@dzenanz
Copy link
Member

dzenanz commented Dec 4, 2025

Compiled with Visual Studio 2026, I get this report when running locally with image size 512:

ystem:              Ryzenator
Processor:           AMD Ryzen 9 5900 12-Core Processor
    Cache:           64
    Clock:           3001
    Physical CPUs:   12
    Logical CPUs:    24
    Virtual Memory:  Total: 81821           Available: 19218
    Physical Memory: Total: 65437           Available: 19945
OSName:              Windows
    Release:         6.2.9200
    Version:         Windows 8
    Platform:        AMD64
    Operating System is 64 bit
ITK Version: 6.0.0
Name Of Probe (Time)          Iterations     Total (s)      Min (s)        Mean (s)       Max (s)        StdDev (s)
IVf3->IRGB-Range              5              4.41809        0.852157       0.883619       0.916879       0.0238361
IVf3->IRGB-Range NT           5              1.55874        0.307114       0.311749       0.318139       0.00430568
IVf3->IRGB-Range NT AsRange   5              1.41355        0.269397       0.28271        0.297235       0.0101519
IVf3->IRGB-Scanline           5              3.69628        0.719785       0.739256       0.777941       0.0246609
IVf3->IRGB-Scanline NT        5              1.74964        0.325232       0.349929       0.379653       0.0197278
IVf3->VId-Range               5              4.55353        0.846602       0.910707       1.02576        0.06808
IVf3->VId-Range NT            5              4.54884        0.86336        0.909769       0.951124       0.0355995
IVf3->VId-Range NT AsRange    5              4.81025        0.85849        0.962049       1.08862        0.0848381
IVf3->VId-Scanline            5              3.93818        0.746597       0.787635       0.883918       0.0548246
IVf3->VId-Scanline NT         5              4.02072        0.77903        0.804143       0.843713       0.0270247
VIf->IVd3-Range               5              4.3705         0.848517       0.874099       0.946619       0.041423
VIf->IVd3-Range NT            5              2.59929        0.491942       0.519858       0.544733       0.0261708
VIf->IVd3-Range NT AsRange    5              2.78581        0.526254       0.557161       0.642648       0.0484499
VIf->IVd3-Scanline            5              4.53976        0.875621       0.907952       0.979755       0.0420488
VIf->IVd3-Scanline NT         5              2.346          0.449374       0.4692         0.488619       0.017489
VIf->VId-Range                5              6.38017        1.21006        1.27603        1.36303        0.0549389
VIf->VId-Range NT             5              7.94991        1.47366        1.58998        1.75424        0.119185
VIf->VId-Range NT AsRange     5              6.19021        1.10183        1.23804        1.36039        0.0926411
VIf->VId-Scanline             5              6.11531        1.19787        1.22306        1.30559        0.0462856
VIf->VId-Scanline NT          5              6.1641         1.17996        1.23282        1.27636        0.0426719

C:\Dev\ITK-vs26\bin\RelWithDebInfo\ImageIterationBenchmark.exe (process 14248) exited with code 0 (0x0).

@dzenanz
Copy link
Member

dzenanz commented Dec 4, 2025

With image size 256:

System:              Ryzenator
Processor:           AMD Ryzen 9 5900 12-Core Processor
    Cache:           64
    Clock:           3001
    Physical CPUs:   12
    Logical CPUs:    24
    Virtual Memory:  Total: 81821           Available: 21831
    Physical Memory: Total: 65437           Available: 22702
OSName:              Windows
    Release:         6.2.9200
    Version:         Windows 8
    Platform:        AMD64
    Operating System is 64 bit
ITK Version: 6.0.0
Name Of Probe (Time)          Iterations     Total (s)      Min (s)        Mean (s)       Max (s)        StdDev (s)
IVf3->IRGB-Range              3              0.306536       0.0989757      0.102179       0.10561        0.00332285
IVf3->IRGB-Range NT           3              0.115145       0.0375679      0.0383817      0.0392609      0.000848389
IVf3->IRGB-Range NT AsRange   3              0.110323       0.0353858      0.0367745      0.0374837      0.00120268
IVf3->IRGB-Scanline           3              0.343899       0.109746       0.114633       0.117514       0.00425475
IVf3->IRGB-Scanline NT        3              0.118689       0.039109       0.039563       0.039798       0.000393281
IVf3->VId-Range               3              0.430354       0.135107       0.143451       0.150231       0.00768234
IVf3->VId-Range NT            3              0.405786       0.130014       0.135262       0.143624       0.00732001
IVf3->VId-Range NT AsRange    3              0.389152       0.127777       0.129717       0.132252       0.00229569
IVf3->VId-Scanline            3              0.371527       0.118763       0.123842       0.128067       0.00471004
IVf3->VId-Scanline NT         3              0.406068       0.124027       0.135356       0.145566       0.0108131
VIf->IVd3-Range               3              0.363257       0.117635       0.121086       0.125803       0.00422912
VIf->IVd3-Range NT            3              0.259692       0.0836656      0.086564       0.0884509      0.00254795
VIf->IVd3-Range NT AsRange    3              0.24384        0.0759907      0.0812802      0.0845337      0.0046211
VIf->IVd3-Scanline            3              0.405856       0.122825       0.135285       0.143172       0.010917
VIf->IVd3-Scanline NT         3              0.199524       0.0628951      0.066508       0.0720153      0.00484625
VIf->VId-Range                3              0.555168       0.180889       0.185056       0.190119       0.00467933
VIf->VId-Range NT             3              0.637885       0.189505       0.212628       0.227129       0.0202401
VIf->VId-Range NT AsRange     3              0.532844       0.173182       0.177615       0.184228       0.00583721
VIf->VId-Scanline             3              0.566867       0.179496       0.188956       0.201652       0.0114274
VIf->VId-Scanline NT          3              0.599435       0.189444       0.199812       0.212887       0.0119537

C:\Dev\ITK-vs26\bin\RelWithDebInfo\ImageIterationBenchmark.exe (process 41536) exited with code 0 (0x0).

@blowekamp
Copy link
Member Author

blowekamp commented Dec 4, 2025

Here are my results with a 256 sized image:

Processor:           Apple M1 Max
    Cache:           131072
    Clock:           0
    Physical CPUs:   10
    Logical CPUs:    10
    Virtual Memory:  Total: 1024            Available: 689
    Physical Memory: Total: 65536           Available: 31383
OSName:              macOS
    Release:         14.8
    Version:         23J21
    Platform:        arm64
    Operating System is 64 bit
ITK Version: 6.0.0
Name Of Probe (Time)          Iterations     Total (s)      Min (s)        Mean (s)       Max (s)        StdDev (s)     
IVf3->IRGB-Range              25             0.899328       0.0329342      0.0359731      0.0628488      0.00708661     
IVf3->IRGB-Range NT           25             0.389894       0.012619       0.0155958      0.0498412      0.00851604     
IVf3->IRGB-Range NT AsRange   25             0.380472       0.013191       0.0152189      0.0430958      0.00671899     
IVf3->IRGB-Scanline           25             1.79517        0.0661981      0.071807       0.105145       0.00832743     
IVf3->IRGB-Scanline NT        25             1.27797        0.0480299      0.0511187      0.0750039      0.00601984     
IVf3->VId-Range               25             0.728552       0.0268691      0.0291421      0.0614741      0.00781228     
IVf3->VId-Range NT            25             0.729723       0.0268271      0.0291889      0.057831       0.00703855     
IVf3->VId-Range NT AsRange    25             0.757548       0.026901       0.0303019      0.0629799      0.00794211     
IVf3->VId-Scanline            25             1.03797        0.0383599      0.0415187      0.0690851      0.00791363     
IVf3->VId-Scanline NT         25             1.02839        0.0383379      0.0411358      0.0657442      0.00641213     
VIf->IVd3-Range               25             1.0207         0.0386071      0.0408278      0.066283       0.00676424     
VIf->IVd3-Range NT            25             0.433348       0.015269       0.0173339      0.044843       0.00667333     
VIf->IVd3-Range NT AsRange    25             0.433969       0.0152111      0.0173588      0.0454051      0.006734       
VIf->IVd3-Scanline            25             1.45441        0.0551069      0.0581764      0.082088       0.005995       
VIf->IVd3-Scanline NT         25             1.28018        0.0485661      0.0512074      0.0772269      0.00642885     
VIf->VId-Range                25             0.749348       0.0269768      0.0299739      0.057488       0.00672359     
VIf->VId-Range NT             25             0.741763       0.027003       0.0296705      0.0587871      0.00715761     
VIf->VId-Range NT AsRange     25             0.743729       0.026968       0.0297492      0.0627439      0.00808991     
VIf->VId-Scanline             25             1.0741         0.0405381      0.042964       0.063534       0.00490833     
VIf->VId-Scanline NT          25             1.05649        0.04021        0.0422598      0.0612209      0.00464216     

Compiler: Apple clang version 16.0.0 (clang-1600.0.26.6)

auto outputIt = outputRange.begin();

const unsigned int componentsPerPixel = itk::NumericTraits<OutputPixelType>::GetLength(*outputIt);
OutputPixelType outputPixel{ *outputIt };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OutputPixelType outputPixel{ *outputIt };
OutputPixelType outputPixelRef{ *outputIt };
OutputPixelType outputPixel = outputPixelRef;

Does this change solve the bug? I my local debugging, it seems to do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My local fix attempt: dzenanz@c696a55

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still has the bug in it. Let me remove that to get valid benchmarks for the range-based-for loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With that fix I get the same performance with or without the range-based-for loop. I have updated my tables.

@blowekamp blowekamp force-pushed the add_iterator_benchmark branch from 01ad87d to 7495758 Compare December 4, 2025 22:00
#include <iomanip>
#include <fstream>


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please place all helper functions (that is basically everything, except for main) in an unnamed namespace.

Comment on lines 56 to 57
itk::ImageRegionIteratorWithIndex<TImage> it(image, region);
for (it.GoToBegin(); !it.IsAtEnd(); ++it)
Copy link
Collaborator

@N-Dekker N-Dekker Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ImageBufferRange here, instead of ImageRegionIteratorWithIndex.

In general, ImageRegionIteratorWithIndex should only be used when you need the (multi-dimensional) index of each pixel. (That is not the case here.) ImageBufferRange is preferred when the entire image buffer is accessed. (That is the case here!)

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks @blowekamp !

Added precommit hook to automatically run clang-format.
@blowekamp blowekamp force-pushed the add_iterator_benchmark branch from 7495758 to b214630 Compare December 9, 2025 14:39
@N-Dekker
Copy link
Collaborator

N-Dekker commented Dec 9, 2025

May I conclude that for these cases, ImageRegionRange has the fastest iterators? 😃

@blowekamp
Copy link
Member Author

May I conclude that for these cases, ImageRegionRange has the fastest iterators? 😃

When not progress need to be reported. The ScanlineIterator only reports progress once per line, I'm not sure there is a similar pattern with the ImageRegionRange iterator.

@blowekamp
Copy link
Member Author

The failure is due to macOS-13 being retired.

@blowekamp blowekamp merged commit 7817cf6 into InsightSoftwareConsortium:master Dec 10, 2025
8 of 10 checks passed
@N-Dekker
Copy link
Collaborator

When not progress need to be reported.

Thanks @blowekamp I'm glad to hear that ImageRegionRange is the fastest! I was afraid that ScanlineIterator might have been faster 😇

The ScanlineIterator only reports progress once per line, I'm not sure there is a similar pattern with the ImageRegionRange iterator.

Good question... I guess the following should do it:

  TotalProgressReporter progress(this, numberOfPixels);
  ImageRegionRange      imageRegionRange(*image, region);
  auto                  it = imageRegionRange.begin();

  for (unsigned int i{}; i < numberOfPixels; ++i)
  {
    *it = 42; // Or something more useful, of course....
    ++it;

    if ((i % numberOfPixelsPerLine) == 0)
    {
      progress.Completed(numberOfPixelsPerLine);
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants