Skip to content

Add some benchmarks for ImageMath - #10071

Merged
radarhere merged 3 commits into
python-pillow:mainfrom
akx:imagemath-benchmarks
Sep 28, 2026
Merged

radarhere merged 3 commits into
python-pillow:mainfrom
akx:imagemath-benchmarks

Conversation

@akx

@akx akx commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Follows in the footsteps of #10033 being broken out of #10030: I'm working on speeding up ImageMath too, but with this we'll get some benchmarks on main :)

@akx
akx marked this pull request as ready for review September 28, 2026 07:19
Comment thread Tests/benchmarks.py
a = make_pillow_image(mode, size)
bench.extra_info["label"] = [f"scalar mul {mode}"]
result = bench(ImageMath.lambda_eval, lambda args: args["a"] * 2, a=a)
assert result.size == a.size

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why isn't this just another parameter on test_imagemath_unary?
pytest.param(lambda a: a * 2, id=...),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You requested my review again, so I think you missed this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, yeah, I did. It's not an unary operation in _imagingmath terms, it's a special case of binary operations.

As noted in the PR description for #10072, the binary operation with one scalar operand case could use its own class of optimizations.

Comment thread Tests/benchmarks.py Outdated
Comment thread Tests/benchmarks.py Outdated
Comment thread Tests/benchmarks.py Outdated
akx and others added 2 commits September 28, 2026 11:55
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@akx
akx requested a review from radarhere September 28, 2026 08:59
@akx akx mentioned this pull request Sep 28, 2026
@radarhere
radarhere merged commit 685e78a into python-pillow:main Sep 28, 2026
50 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants