Skip to content

Commit d36cc47

Browse files
committed
test: image_span_test reduce benchmark load for debug and CI renders (#4951)
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. Also conform simd_test to the usual standard `-iters` used elsewhere instead of being the one place that uses `-iterations`. --------- Signed-off-by: Larry Gritz <[email protected]>
1 parent d3b2dd1 commit d36cc47

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/libOpenImageIO/image_span_test.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <OpenImageIO/half.h>
77

8+
#include <OpenImageIO/argparse.h>
89
#include <OpenImageIO/benchmark.h>
910
#include <OpenImageIO/fmath.h>
1011
#include <OpenImageIO/imageio.h>
@@ -18,6 +19,9 @@
1819
using namespace OIIO;
1920

2021

22+
static int ntrials = 5;
23+
24+
2125

2226
template<typename T>
2327
void
@@ -195,6 +199,7 @@ test_image_span_copy_image()
195199

196200
// Benchmark old (ptr) versus new (span) copy_image functions
197201
Benchmarker bench;
202+
bench.trials(ntrials);
198203
bench.units(Benchmarker::Unit::us);
199204

200205
bench(Strutil::format(" copy_image image_span {}", label),
@@ -266,6 +271,7 @@ test_image_span_contiguize()
266271

267272
// Benchmark old (ptr) versus new (span) contiguize functions
268273
Benchmarker bench;
274+
bench.trials(ntrials);
269275
bench.units(Benchmarker::Unit::us);
270276

271277
bench(Strutil::format(" contiguize image_span {}", label), [&]() {
@@ -332,6 +338,7 @@ test_image_span_convert_image()
332338

333339
// Benchmark old (ptr) versus new (span) contiguize functions
334340
Benchmarker bench;
341+
bench.trials(ntrials);
335342
bench.units(Benchmarker::Unit::ms);
336343

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

420427
Benchmarker bench;
428+
bench.trials(ntrials);
421429
bench.units(Benchmarker::Unit::us);
422430
float sum = 0.0f;
423431

@@ -442,6 +450,7 @@ benchmark_image_span_passing()
442450

443451
// Do it all again for a SMALL image
444452
bench.units(Benchmarker::Unit::ns);
453+
bench.trials(ntrials);
445454
int small = 16;
446455
image_span<const float> smispan(sbuf.data(), nchans, small, small, 1);
447456
bench(" pass by value (small)",
@@ -544,9 +553,36 @@ test_image_span_within_span()
544553

545554

546555

556+
static void
557+
getargs(int argc, char* argv[])
558+
{
559+
ArgParse ap;
560+
ap.intro(
561+
"image_span_test -- unit test and benchmarks for OpenImageIO/image_span.h\n" OIIO_INTRO_STRING)
562+
.usage("image_span_test [options]");
563+
564+
// ap.arg("--iterations %d", &iterations)
565+
// .help(Strutil::fmt::format("Number of iterations (default: {})",
566+
// iterations));
567+
ap.arg("--trials %d", &ntrials).help("Number of trials");
568+
569+
ap.parse_args(argc, (const char**)argv);
570+
}
571+
572+
573+
547574
int
548-
main(int /*argc*/, char* /*argv*/[])
575+
main(int argc, char* argv[])
549576
{
577+
#if !defined(NDEBUG) || defined(OIIO_CI) || defined(OIIO_CODE_COVERAGE)
578+
// For the sake of test time, reduce the default iterations for DEBUG,
579+
// CI, and code coverage builds. Explicit use of --trials
580+
// will override this, since it comes before the getargs() call.
581+
ntrials = 1;
582+
#endif
583+
584+
getargs(argc, argv);
585+
550586
test_image_span<float>();
551587
test_image_span<const float>();
552588
test_image_span<uint16_t>();

src/libutil/simd_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ getargs(int argc, char* argv[])
4343
OIIO_INTRO_STRING)
4444
.usage("simd_test [options]");
4545

46-
ap.arg("--iterations %d", &iterations)
46+
ap.arg("--iters %d", &iterations)
4747
.help(Strutil::fmt::format("Number of iterations (default: {})", iterations));
48+
ap.arg("--iterations %d", &iterations)
49+
.hidden(); // obsolete synonym for --iters
4850
ap.arg("--trials %d", &ntrials)
4951
.help("Number of trials");
5052

0 commit comments

Comments
 (0)