Skip to content

Commit cc794f2

Browse files
authored
ci: add facility for benchmarking as part of CI (#4745)
Make it so that CI test cases that set the GHA variable "benchmark" to 1 will add a benchmarking step to the workflow that runs a new ci-benchmark.bash script. The script runs selected unit tests containing benchmarks (currently, only image_span_test, but we can amend later as needed). Those designated tests are run, and their output both echoed to the log for that step and also put in build/benchmarks/TESTNAME and saved as a build artifact for optional download. Most test cases will not turn benchmarking on -- it probably will end up adding a few minutes so do it very selectively (once per major platform or compiler version is plenty). I would have previously guessed that any attempts at benchmarking on GHA runners was doomed, but in practice, I'm surprised to find that there's almost as much run-to-run consistency as I find doing casual benchmarks on my own machine. As such, I think this can be a handy way to do some rough benchmarking using CI, to compare platforms or compilers, or verify that changes we want to make don't introduce performance regressions. Caveats to remember in the future: * Take it all with a big grain of salt, and watch the benchmark numbers for the trial-to-trial range of times -- wide variation means that the numbers probably can't be trusted. * The GH runners themselves may change without warning, so beware benchmark stability over time, or if they ever have pools of heterogeneous machine generations/configurations. * While my results indicate a decent amount of timing reliability for purely computational tests, I assume that there will be enormous run-to-run variation in anything involving I/O or networking. So this is unlikely to be a fruitful way of testing for performance regressions in image format I/O speed (but probably is useful for a variety of in-memory operations). * As we add more unit tests to what we benchmark in the future, keep an eye how much time we're spending running these benchmarks. A few minutes on a small subset of the test jobs is probably fine, but I wouldn't want it to make the overall wait for a full CI run to become substantially longer because of it. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 6cb8714 commit cc794f2

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

.github/workflows/build-steps.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ on:
5050
type: string
5151
abi_check:
5252
type: string
53+
benchmark:
54+
type: string
5355
build_docs:
5456
type: string
5557
clang_format:
@@ -145,6 +147,10 @@ jobs:
145147
if: inputs.skip_tests != '1'
146148
shell: bash
147149
run: src/build-scripts/ci-test.bash
150+
- name: Benchmarks
151+
if: inputs.benchmark == '1'
152+
shell: bash
153+
run: src/build-scripts/ci-benchmark.bash
148154
- name: clang-format
149155
if: inputs.clang_format == '1'
150156
shell: bash
@@ -193,13 +199,14 @@ jobs:
193199
time make sphinx
194200
- name: Upload testsuite debugging artifacts
195201
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
196-
if: ${{ failure() || inputs.build_docs == '1'}}
202+
if: ${{ failure() || inputs.build_docs == '1' || inputs.benchmark == '1' }}
197203
with:
198204
name: oiio-${{github.job}}-${{inputs.nametag}}
199205
path: |
200206
build/cmake-save
201207
build/compat_reports
202208
build/sphinx
209+
build/benchmarks
203210
build/testsuite/*/*.*
204211
!build/testsuite/oiio-images
205212
!build/testsuite/openexr-images

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ jobs:
200200
- name: Testsuite
201201
if: matrix.skip_tests != '1'
202202
run: src/build-scripts/ci-test.bash
203+
- name: Benchmarks
204+
if: matrix.benchmark == '1'
205+
shell: bash
206+
run: src/build-scripts/ci-benchmark.bash
203207
- name: Check out ABI standard
204208
if: matrix.abi_check != ''
205209
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -232,6 +236,7 @@ jobs:
232236
build/cmake-save
233237
build/compat_reports
234238
build/sphinx
239+
build/benchmarks
235240
build/testsuite/*/*.*
236241
!build/testsuite/oiio-images
237242
!build/testsuite/openexr-images
@@ -267,6 +272,7 @@ jobs:
267272
skip_build: ${{ matrix.skip_build }}
268273
skip_tests: ${{ matrix.skip_tests }}
269274
abi_check: ${{ matrix.abi_check }}
275+
benchmark: ${{ matrix.benchmark }}
270276
build_docs: ${{ matrix.build_docs }}
271277
clang_format: ${{ matrix.clang_format }}
272278
generator: ${{ matrix.generator }}
@@ -312,6 +318,7 @@ jobs:
312318
python_ver: "3.10"
313319
pybind11_ver: v2.10.0
314320
simd: "avx2,f16c"
321+
benchmark: 1
315322
setenvs: export USE_OPENVDB=0
316323
xOPENCOLORIO_CXX=g++
317324
UHDR_CMAKE_C_COMPILER=gcc
@@ -326,6 +333,7 @@ jobs:
326333
simd: "avx2,f16c"
327334
fmt_ver: 10.1.1
328335
pybind11_ver: v2.12.0
336+
benchmark: 1
329337
setenvs: PUGIXML_VERSION=v1.14
330338
- desc: VFX2024 clang/C++17 py3.11 exr3.2 ocio2.3
331339
nametag: linux-vfx2024.clang
@@ -337,6 +345,7 @@ jobs:
337345
simd: "avx2,f16c"
338346
fmt_ver: 10.1.1
339347
pybind11_ver: v2.12.0
348+
benchmark: 1
340349
setenvs: PUGIXML_VERSION=v1.14
341350
- desc: VFX2025 gcc11/C++17 py3.11 exr3.3 ocio2.4
342351
nametag: linux-vfx2025
@@ -346,6 +355,7 @@ jobs:
346355
simd: "avx2,f16c"
347356
fmt_ver: 11.1.4
348357
pybind11_ver: v2.13.6
358+
benchmark: 1
349359
setenvs: PUGIXML_VERSION=v1.15
350360
- desc: Sanitizers
351361
nametag: sanitizer
@@ -431,6 +441,7 @@ jobs:
431441
pybind11_ver: master
432442
python_ver: "3.12"
433443
simd: avx2,f16c
444+
benchmark: 1
434445
setenvs: export LIBJPEGTURBO_VERSION=main
435446
LIBRAW_VERSION=master
436447
LIBTIFF_VERSION=master
@@ -529,6 +540,7 @@ jobs:
529540
simd: ${{ matrix.simd }}
530541
skip_build: ${{ matrix.skip_build }}
531542
skip_tests: ${{ matrix.skip_tests }}
543+
benchmark: ${{ matrix.benchmark }}
532544
abi_check: ${{ matrix.abi_check }}
533545
build_docs: ${{ matrix.build_docs }}
534546
generator: ${{ matrix.generator }}
@@ -550,6 +562,7 @@ jobs:
550562
simd: sse4.2,avx2
551563
ctest_test_timeout: 1200
552564
setenvs: export MACOSX_DEPLOYMENT_TARGET=12.0
565+
benchmark: 1
553566
- desc: MacOS-14-ARM aclang15/C++20/py3.12
554567
runner: macos-14
555568
nametag: macos14-arm-py312
@@ -564,6 +577,7 @@ jobs:
564577
cxx_compiler: clang++
565578
cxx_std: 20
566579
python_ver: "3.13"
580+
benchmark: 1
567581

568582

569583
#
@@ -592,6 +606,7 @@ jobs:
592606
simd: ${{ matrix.simd }}
593607
skip_build: ${{ matrix.skip_build }}
594608
skip_tests: ${{ matrix.skip_tests }}
609+
benchmark: ${{ matrix.benchmark }}
595610
abi_check: ${{ matrix.abi_check }}
596611
build_docs: ${{ matrix.build_docs }}
597612
generator: ${{ matrix.generator }}
@@ -624,3 +639,4 @@ jobs:
624639
generator: "Visual Studio 17 2022"
625640
python_ver: "3.9"
626641
setenvs: export OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1
642+
benchmark: 1
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Contributors to the OpenImageIO project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
6+
7+
BUILD_BIN_DIR=build/bin
8+
if [[ "${RUNNER_OS}" == "Windows" ]] ; then
9+
BUILD_BIN_DIR+=/${CMAKE_BUILD_TYPE}
10+
fi
11+
12+
ls build
13+
ls $BUILD_BIN_DIR
14+
15+
mkdir -p build/benchmarks
16+
for t in image_span_test ; do
17+
echo
18+
echo
19+
echo "$t"
20+
echo "========================================================"
21+
${BUILD_BIN_DIR}/$t > build/benchmarks/$t.out
22+
cat build/benchmarks/$t.out
23+
echo "========================================================"
24+
echo "========================================================"
25+
echo
26+
done

0 commit comments

Comments
 (0)