Skip to content
Merged
Changes from all commits
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
31 changes: 31 additions & 0 deletions Tests/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,37 @@ def test_offset(bench: BenchmarkFixture, mode: str, size: tuple[int, int]) -> No
bench(ImageChops.offset, im, 123, 45)


@pytest.mark.benchmark(group="compare")
@pytest.mark.parametrize("scenario", ["equal", "one-pixel", "inverted"])
@pytest.mark.parametrize("mode", [*MODES, "I;16"])
@pytest.mark.parametrize("size", SIZES, ids=_format_size)
def test_equality(
bench: BenchmarkFixture,
mode: str,
size: tuple[int, int],
scenario: str,
) -> None:
im1 = make_pillow_image(mode, size)
if scenario == "inverted": # Differs in almost every pixel
im2 = ImageChops.invert(im1)
elif scenario == "one-pixel":
# Differs in a single pixel halfway through the image in raster order
xy = ((im1.width * im1.height // 2) % im1.width, im1.height // 2)
im2 = im1.copy()
value = im2.getpixel(xy)
assert value is not None
if isinstance(value, tuple):
value = tuple(255 - v for v in value)
else:
value = 255 - value
im2.putpixel(xy, value)
else: # Equal
im2 = im1.copy()
bench.extra_info["label"] = [scenario]

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.

Suggested change
bench.extra_info["label"] = [scenario]
bench.extra_info["label"] = scenario

@akx akx Sep 21, 2026

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.

Other benchmarks also wrap a single parameter in a list. This follows that style.

result = bench(lambda: im1 == im2)
assert result is (scenario == "equal")


@pytest.mark.benchmark(group="extrema")
@pytest.mark.parametrize("mode", ["L", "LA", "I", "F", "RGB", "RGBA", "CMYK"])
@pytest.mark.parametrize("size", SIZES, ids=_format_size)
Expand Down
Loading