Skip to content

Commit b81844a

Browse files
author
Claude Subagent
committed
feat: Add parametrized benchmarks for Zarr v2 and v3 formats
- Extends existing read/write benchmarks to test both v2 and v3 - Parametrizes on zarr_format, compression, layout, and store type - Skips v2 + sharding combinations (not supported in v2) - Reuses existing test structure per maintainer feedback - Provides performance comparison across Zarr versions Addresses feedback: 'better to reuse existing tests with parametrization'
1 parent b6d3ae2 commit b81844a

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

changes/3757.feature.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Add parametrized benchmark tests for both Zarr v2 and v3 formats
2+
3+
- Extends existing read/write benchmarks to test both v2 and v3
4+
- Parametrizes on zarr_format, compression, layout, and store type
5+
- Skips v2 + sharding combinations (not supported in v2)
6+
- Provides performance comparison between Zarr versions

tests/benchmarks/test_e2e.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from zarr.abc.store import Store
1515
from zarr.core.common import NamedConfig
16+
1617
from operator import getitem, setitem
1718
from typing import Any, Literal
1819

@@ -21,13 +22,13 @@
2122
from zarr import create_array
2223

2324
CompressorName = Literal["gzip"] | None
25+
ZarrFormat = Literal[2, 3]
2426

2527
compressors: dict[CompressorName, NamedConfig[Any, Any] | None] = {
2628
None: None,
2729
"gzip": {"name": "gzip", "configuration": {"level": 1}},
2830
}
2931

30-
3132
layouts: tuple[Layout, ...] = (
3233
# No shards, just 1000 chunks
3334
Layout(shape=(1_000_000,), chunks=(1000,), shards=None),
@@ -38,17 +39,28 @@
3839
)
3940

4041

42+
@pytest.mark.parametrize("zarr_format", [2, 3])
4143
@pytest.mark.parametrize("compression_name", [None, "gzip"])
4244
@pytest.mark.parametrize("layout", layouts, ids=str)
4345
@pytest.mark.parametrize("store", ["memory", "local"], indirect=["store"])
4446
def test_write_array(
45-
store: Store, layout: Layout, compression_name: CompressorName, benchmark: BenchmarkFixture
47+
store: Store,
48+
layout: Layout,
49+
compression_name: CompressorName,
50+
zarr_format: ZarrFormat,
51+
benchmark: BenchmarkFixture,
4652
) -> None:
4753
"""
48-
Test the time required to fill an array with a single value
54+
Test the time required to fill an array with a single value.
55+
Parametrized to benchmark both Zarr v2 and v3 formats.
4956
"""
57+
# Skip v2 tests with sharding (not supported in v2)
58+
if zarr_format == 2 and layout.shards is not None:
59+
pytest.skip("Sharding not supported in Zarr v2")
60+
5061
arr = create_array(
5162
store,
63+
zarr_format=zarr_format,
5264
dtype="uint8",
5365
shape=layout.shape,
5466
chunks=layout.chunks,
@@ -60,17 +72,28 @@ def test_write_array(
6072
benchmark(setitem, arr, Ellipsis, 1)
6173

6274

75+
@pytest.mark.parametrize("zarr_format", [2, 3])
6376
@pytest.mark.parametrize("compression_name", [None, "gzip"])
6477
@pytest.mark.parametrize("layout", layouts, ids=str)
6578
@pytest.mark.parametrize("store", ["memory", "local"], indirect=["store"])
6679
def test_read_array(
67-
store: Store, layout: Layout, compression_name: CompressorName, benchmark: BenchmarkFixture
80+
store: Store,
81+
layout: Layout,
82+
compression_name: CompressorName,
83+
zarr_format: ZarrFormat,
84+
benchmark: BenchmarkFixture,
6885
) -> None:
6986
"""
70-
Test the time required to fill an array with a single value
87+
Test the time required to read an array.
88+
Parametrized to benchmark both Zarr v2 and v3 formats.
7189
"""
90+
# Skip v2 tests with sharding (not supported in v2)
91+
if zarr_format == 2 and layout.shards is not None:
92+
pytest.skip("Sharding not supported in Zarr v2")
93+
7294
arr = create_array(
7395
store,
96+
zarr_format=zarr_format,
7497
dtype="uint8",
7598
shape=layout.shape,
7699
chunks=layout.chunks,

0 commit comments

Comments
 (0)