-
-
Notifications
You must be signed in to change notification settings - Fork 366
add benchmarks using pytest-benchmark and codspeed #3562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
ef5db51
4c2a935
3e5c6cb
fc3388d
da64194
ba2c4cf
009f739
7b26982
c0342ee
800b64c
f86291b
dd76776
90502a6
5e0c228
f613b29
602d79f
523f565
9eb4bb6
c9ab694
0ecc190
b657e59
3033fbf
4394226
7e4ca58
27ca426
93ea2e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: CodSpeed Benchmarks | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" # or "master" | ||
| pull_request: | ||
| # `workflow_dispatch` allows CodSpeed to trigger backtest | ||
| # performance analysis in order to generate initial data. | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| benchmarks: | ||
| name: Run benchmarks | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 # grab all branches and tags | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| - name: Install Hatch | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install hatch | ||
| - name: Run the benchmarks | ||
| uses: CodSpeedHQ/action@v4 | ||
| with: | ||
| mode: instrumentation | ||
| run: hatch run test.py3.11-1.26-minimal:run-benchmark | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add continuous performance benchmarking infrastructure. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """ | ||
| Test the basic end-to-end read/write performance of Zarr | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pytest_benchmark.fixture import BenchmarkFixture | ||
|
|
||
| from zarr.abc.store import Store | ||
| from zarr.core.common import NamedConfig | ||
| from operator import getitem, setitem | ||
| from typing import Any, Literal | ||
|
|
||
| import pytest | ||
|
|
||
| from zarr import create_array | ||
|
|
||
| CompressorName = Literal["gzip"] | None | ||
|
|
||
| compressors: dict[CompressorName, NamedConfig[Any, Any] | None] = { | ||
| None: None, | ||
| "gzip": {"name": "gzip", "configuration": {"level": 1}}, | ||
| } | ||
|
|
||
|
|
||
| @dataclass(kw_only=True, frozen=True) | ||
| class Layout: | ||
| shape: tuple[int, ...] | ||
| chunks: tuple[int, ...] | ||
| shards: tuple[int, ...] | None | ||
|
|
||
|
|
||
| layouts: tuple[Layout, ...] = ( | ||
| Layout(shape=(16,), chunks=(1,), shards=None), | ||
| Layout(shape=(16,), chunks=(16,), shards=None), | ||
| Layout(shape=(16,), chunks=(1,), shards=(1,)), | ||
| Layout(shape=(16,), chunks=(1,), shards=(16,)), | ||
| Layout(shape=(16,) * 2, chunks=(1,) * 2, shards=None), | ||
| Layout(shape=(16,) * 2, chunks=(16,) * 2, shards=None), | ||
| Layout(shape=(16,) * 2, chunks=(1,) * 2, shards=(1,) * 2), | ||
| Layout(shape=(16,) * 2, chunks=(1,) * 2, shards=(16,) * 2), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("compression_name", [None, "gzip"]) | ||
| @pytest.mark.parametrize("layout", layouts) | ||
| @pytest.mark.parametrize("store", ["memory", "local", "zip"], indirect=["store"]) | ||
| def test_write_array( | ||
| store: Store, layout: Layout, compression_name: CompressorName, benchmark: BenchmarkFixture | ||
| ) -> None: | ||
| """ | ||
| Test the time required to fill an array with a single value | ||
| """ | ||
| arr = create_array( | ||
| store, | ||
| dtype="uint8", | ||
| shape=layout.shape, | ||
| chunks=layout.chunks, | ||
| shards=layout.shards, | ||
| compressors=compressors[compression_name], # type: ignore[arg-type] | ||
| fill_value=0, | ||
| ) | ||
|
|
||
| benchmark(setitem, arr, Ellipsis, 1) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("compression_name", [None, "gzip"]) | ||
| @pytest.mark.parametrize("layout", layouts) | ||
| @pytest.mark.parametrize("store", ["memory", "local"], indirect=["store"]) | ||
| def test_read_array( | ||
| store: Store, layout: Layout, compression_name: CompressorName, benchmark: BenchmarkFixture | ||
| ) -> None: | ||
| """ | ||
| Test the time required to fill an array with a single value | ||
| """ | ||
| arr = create_array( | ||
| store, | ||
| dtype="uint8", | ||
| shape=layout.shape, | ||
| chunks=layout.chunks, | ||
| shards=layout.shards, | ||
| compressors=compressors[compression_name], # type: ignore[arg-type] | ||
| fill_value=0, | ||
| ) | ||
| arr[:] = 1 | ||
| benchmark(getitem, arr, Ellipsis) |
Uh oh!
There was an error while loading. Please reload this page.