-
Notifications
You must be signed in to change notification settings - Fork 9
ENH: Add benchmark for iterator loop comparison #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add benchmark for iterator loop comparison #105
Conversation
54f1fbf to
01ad87d
Compare
|
Compiled with Visual Studio 2026, I get this report when running locally with image size 512: |
|
With image size 256: |
|
Here are my results with a 256 sized image: 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 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| OutputPixelType outputPixel{ *outputIt }; | |
| OutputPixelType outputPixelRef{ *outputIt }; | |
| OutputPixelType outputPixel = outputPixelRef; |
Does this change solve the bug? I my local debugging, it seems to do so.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
01ad87d to
7495758
Compare
| #include <iomanip> | ||
| #include <fstream> | ||
|
|
||
|
|
There was a problem hiding this comment.
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.
| itk::ImageRegionIteratorWithIndex<TImage> it(image, region); | ||
| for (it.GoToBegin(); !it.IsAtEnd(); ++it) |
There was a problem hiding this comment.
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!)
thewtex
left a comment
There was a problem hiding this 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.
7495758 to
b214630
Compare
|
May I conclude that for these cases, |
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. |
|
The failure is due to macOS-13 being retired. |
7817cf6
into
InsightSoftwareConsortium:master
Thanks @blowekamp I'm glad to hear that ImageRegionRange is the fastest! I was afraid that ScanlineIterator might have been faster 😇
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);
}
} |
No description provided.