Skip to content
Merged
Changes from 1 commit
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
40 changes: 39 additions & 1 deletion src/libOpenImageIO/image_span_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <OpenImageIO/half.h>

#include <OpenImageIO/argparse.h>
#include <OpenImageIO/benchmark.h>
#include <OpenImageIO/fmath.h>
#include <OpenImageIO/imageio.h>
Expand All @@ -18,6 +19,10 @@
using namespace OIIO;


static int iterations = 0; // 1000000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like iterations is unused. It's only set, but never passed into something like bench.iterations(...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixing

static int ntrials = 5;



template<typename T>
void
Expand Down Expand Up @@ -195,6 +200,7 @@ test_image_span_copy_image()

// Benchmark old (ptr) versus new (span) copy_image functions
Benchmarker bench;
bench.trials(ntrials);
bench.units(Benchmarker::Unit::us);

bench(Strutil::format(" copy_image image_span {}", label),
Expand Down Expand Up @@ -266,6 +272,7 @@ test_image_span_contiguize()

// Benchmark old (ptr) versus new (span) contiguize functions
Benchmarker bench;
bench.trials(ntrials);
bench.units(Benchmarker::Unit::us);

bench(Strutil::format(" contiguize image_span {}", label), [&]() {
Expand Down Expand Up @@ -332,6 +339,7 @@ test_image_span_convert_image()

// Benchmark old (ptr) versus new (span) contiguize functions
Benchmarker bench;
bench.trials(ntrials);
bench.units(Benchmarker::Unit::ms);

bench(Strutil::format(" convert_image image_span {}", label),
Expand Down Expand Up @@ -418,6 +426,7 @@ benchmark_image_span_passing()
image_span<const float> ispan(sbuf.data(), nchans, xres, yres, 1);

Benchmarker bench;
bench.trials(ntrials);
bench.units(Benchmarker::Unit::us);
float sum = 0.0f;

Expand All @@ -442,6 +451,7 @@ benchmark_image_span_passing()

// Do it all again for a SMALL image
bench.units(Benchmarker::Unit::ns);
bench.trials(ntrials);
int small = 16;
image_span<const float> smispan(sbuf.data(), nchans, small, small, 1);
bench(" pass by value (small)",
Expand Down Expand Up @@ -544,9 +554,37 @@ test_image_span_within_span()



static void
getargs(int argc, char* argv[])
{
ArgParse ap;
ap.intro(
"image_span_test -- unit test and benchmarks for OpenImageIO/image_span.h\n" OIIO_INTRO_STRING)
.usage("image_span_test [options]");

ap.arg("--iterations %d", &iterations)
Copy link
Contributor

@jessey-git jessey-git Nov 11, 2025

Choose a reason for hiding this comment

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

Funny stat: There's currently 14 instances of tests that use --iters and 14 instances that use --iterations. This new addition here would tip the scale in favor of using the full --iterations name -- should somebody make them all the same and create a new PR for that?

[EDIT] Actually I miscounted, there's just 1 other test, simd_test.cpp that uses the full --iterations name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aha, fixing simd_test

.help(Strutil::fmt::format("Number of iterations (default: {})",
iterations));
ap.arg("--trials %d", &ntrials).help("Number of trials");

ap.parse_args(argc, (const char**)argv);
}



int
main(int /*argc*/, char* /*argv*/[])
main(int argc, char* argv[])
{
#if !defined(NDEBUG) || defined(OIIO_CI) || defined(OIIO_CODE_COVERAGE)
// For the sake of test time, reduce the default iterations for DEBUG,
// CI, and code coverage builds. Explicit use of --iters or --trials
// will override this, since it comes before the getargs() call.
iterations /= 10;
ntrials = 1;
#endif

getargs(argc, argv);

test_image_span<float>();
test_image_span<const float>();
test_image_span<uint16_t>();
Expand Down
Loading