Skip to content

Commit cd2e0ab

Browse files
author
Test User
committed
Add benchmark tests for Zarr v2 format reading and writing
1 parent 420f11c commit cd2e0ab

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

changes/3757.feature.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add benchmark tests for Zarr v2 format reading and writing performance.
2+
Benchmarks test reading and writing Zarr v2 arrays with different compression settings and chunk layouts.

tests/benchmarks/test_e2e.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,68 @@ def test_read_array(
8080
)
8181
arr[:] = 1
8282
benchmark(getitem, arr, Ellipsis)
83+
84+
85+
# Zarr v2 benchmark tests
86+
87+
v2_compressors: dict[CompressorName, NamedConfig[Any, Any] | None] = {
88+
None: None,
89+
"gzip": {"name": "gzip", "configuration": {"level": 1}},
90+
}
91+
92+
v2_layouts: tuple[Layout, ...] = (
93+
# No shards, just 1000 chunks
94+
Layout(shape=(1_000_000,), chunks=(1000,), shards=None),
95+
# Larger chunks (v2 doesn't support shards, so we skip the other layouts)
96+
Layout(shape=(1_000_000,), chunks=(10000,), shards=None),
97+
)
98+
99+
100+
@pytest.mark.parametrize("compression_name", [None, "gzip"])
101+
@pytest.mark.parametrize("layout", v2_layouts, ids=str)
102+
@pytest.mark.parametrize("store", ["memory", "local"], indirect=["store"])
103+
def test_read_array_v2(
104+
store: Store, layout: Layout, compression_name: CompressorName, benchmark: BenchmarkFixture
105+
) -> None:
106+
"""
107+
Test the time required to read a Zarr v2 array
108+
109+
This benchmark tests reading performance of Zarr v2 format arrays,
110+
which only supports traditional chunking without shards.
111+
"""
112+
arr = create_array(
113+
store,
114+
zarr_format=2,
115+
dtype="uint8",
116+
shape=layout.shape,
117+
chunks=layout.chunks,
118+
compressors=v2_compressors[compression_name], # type: ignore[arg-type]
119+
fill_value=0,
120+
)
121+
arr[:] = 1
122+
benchmark(getitem, arr, Ellipsis)
123+
124+
125+
@pytest.mark.parametrize("compression_name", [None, "gzip"])
126+
@pytest.mark.parametrize("layout", v2_layouts, ids=str)
127+
@pytest.mark.parametrize("store", ["memory", "local"], indirect=["store"])
128+
def test_write_array_v2(
129+
store: Store, layout: Layout, compression_name: CompressorName, benchmark: BenchmarkFixture
130+
) -> None:
131+
"""
132+
Test the time required to write a Zarr v2 array
133+
134+
This benchmark tests writing performance of Zarr v2 format arrays,
135+
which only supports traditional chunking without shards.
136+
"""
137+
arr = create_array(
138+
store,
139+
zarr_format=2,
140+
dtype="uint8",
141+
shape=layout.shape,
142+
chunks=layout.chunks,
143+
compressors=v2_compressors[compression_name], # type: ignore[arg-type]
144+
fill_value=0,
145+
)
146+
147+
benchmark(setitem, arr, Ellipsis, 1)

0 commit comments

Comments
 (0)