From ce7c6f53e0b8ad253c4db8152ddfac4e52135fc6 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sun, 9 Nov 2025 09:44:29 -0800 Subject: [PATCH 1/2] test: image_span_test reduce benchmark load for debug and CI renders Almost all the other unit tests do this, just adding it to image_span_test: automatic reduction in test load for CI and debug renders by doing fewer time trials. This cuts down on runtime for CI, but stil exercises the test code. Command line arguments allow you to override, in cases where you need really good timing fidelity even for a debug run. Signed-off-by: Larry Gritz --- src/libOpenImageIO/image_span_test.cpp | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/libOpenImageIO/image_span_test.cpp b/src/libOpenImageIO/image_span_test.cpp index ad7e357245..7ec599a009 100644 --- a/src/libOpenImageIO/image_span_test.cpp +++ b/src/libOpenImageIO/image_span_test.cpp @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -18,6 +19,10 @@ using namespace OIIO; +static int iterations = 0; // 1000000; +static int ntrials = 5; + + template void @@ -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), @@ -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), [&]() { @@ -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), @@ -418,6 +426,7 @@ benchmark_image_span_passing() image_span ispan(sbuf.data(), nchans, xres, yres, 1); Benchmarker bench; + bench.trials(ntrials); bench.units(Benchmarker::Unit::us); float sum = 0.0f; @@ -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 smispan(sbuf.data(), nchans, small, small, 1); bench(" pass by value (small)", @@ -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) + .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(); test_image_span(); test_image_span(); From 2f5522706aa24a17e3770effd5beab21d3d43c62 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Mon, 10 Nov 2025 23:28:48 -0800 Subject: [PATCH 2/2] Revision: eliminate unused 'iterations' and conform simd_test to the usual standard used elsewhere Signed-off-by: Larry Gritz --- src/libOpenImageIO/image_span_test.cpp | 12 +++++------- src/libutil/simd_test.cpp | 4 +++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libOpenImageIO/image_span_test.cpp b/src/libOpenImageIO/image_span_test.cpp index 7ec599a009..87aeb3dfb4 100644 --- a/src/libOpenImageIO/image_span_test.cpp +++ b/src/libOpenImageIO/image_span_test.cpp @@ -19,8 +19,7 @@ using namespace OIIO; -static int iterations = 0; // 1000000; -static int ntrials = 5; +static int ntrials = 5; @@ -562,9 +561,9 @@ getargs(int argc, char* argv[]) "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) - .help(Strutil::fmt::format("Number of iterations (default: {})", - iterations)); + // ap.arg("--iterations %d", &iterations) + // .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); @@ -577,9 +576,8 @@ 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 + // CI, and code coverage builds. Explicit use of --trials // will override this, since it comes before the getargs() call. - iterations /= 10; ntrials = 1; #endif diff --git a/src/libutil/simd_test.cpp b/src/libutil/simd_test.cpp index b34fb6bbd6..31c1b70792 100644 --- a/src/libutil/simd_test.cpp +++ b/src/libutil/simd_test.cpp @@ -43,8 +43,10 @@ getargs(int argc, char* argv[]) OIIO_INTRO_STRING) .usage("simd_test [options]"); - ap.arg("--iterations %d", &iterations) + ap.arg("--iters %d", &iterations) .help(Strutil::fmt::format("Number of iterations (default: {})", iterations)); + ap.arg("--iterations %d", &iterations) + .hidden(); // obsolete synonym for --iters ap.arg("--trials %d", &ntrials) .help("Number of trials");