Skip to content
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

testing: imagebuf_test add benchmarks for iterator traversal #4007

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/libOpenImageIO/imagebuf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,62 @@ test_mutable_iterator_with_imagecache()



void
time_iterators()
{
print("Timing iterator operations:\n");
const int rez = 4096, nchans = 4;
ImageSpec spec(rez, rez, nchans, TypeFloat);
ImageBuf img(spec);
ImageBufAlgo::fill(img, { 0.25f, 0.5f, 0.75f, 1.0f });

Benchmarker bench;
double sum = 0.0f;
bench("Read traversal with ConstIterator", [&]() {
sum = 0.0f;
for (ImageBuf::ConstIterator<float> it(img); !it.done(); ++it) {
for (int c = 0; c < nchans; ++c)
sum += it[c];
}
});
OIIO_CHECK_EQUAL(sum, 2.5 * rez * rez);
bench("Read traversal with Iterator", [&]() {
sum = 0.0f;
for (ImageBuf::Iterator<float> it(img); !it.done(); ++it) {
for (int c = 0; c < nchans; ++c)
sum += it[c];
}
});
OIIO_CHECK_EQUAL(sum, 2.5 * rez * rez);
bench("Read traversal with pointer", [&]() {
sum = 0.0f;
const float* it = (const float*)img.localpixels();
for (int y = 0; y < rez; ++y)
for (int x = 0; x < rez; ++x, it += 4) {
for (int c = 0; c < nchans; ++c)
sum += it[c];
}
});
OIIO_CHECK_EQUAL(sum, 2.5 * rez * rez);
bench("Write traversal with Iterator", [&]() {
ImageBuf::Iterator<float> it(img);
for (ImageBuf::Iterator<float> it(img); !it.done(); ++it) {
for (int c = 0; c < nchans; ++c)
it[c] = 0.5f;
}
});
bench("Write traversal with pointer", [&]() {
float* it = (float*)img.localpixels();
for (int y = 0; y < rez; ++y)
for (int x = 0; x < rez; ++x, it += 4) {
for (int c = 0; c < nchans; ++c)
it[c] = 0.5f;
}
});
}



int
main(int /*argc*/, char* /*argv*/[])
{
Expand All @@ -563,6 +619,7 @@ main(int /*argc*/, char* /*argv*/[])
iterator_wrap_test<ImageBuf::ConstIterator<float>>(ImageBuf::WrapMirror,
"mirror");
test_mutable_iterator_with_imagecache();
time_iterators();

ImageBuf_test_appbuffer();
ImageBuf_test_appbuffer_strided();
Expand Down
Loading