-
-
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
Open
d-v-b
wants to merge
26
commits into
zarr-developers:main
Choose a base branch
from
d-v-b:chore/benchmarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ef5db51
add benchmarks
d-v-b 4c2a935
remove failing zipstore
d-v-b 3e5c6cb
don't do benchmarking in default pytest runs
d-v-b fc3388d
changelog
d-v-b da64194
codspeed workflow
d-v-b ba2c4cf
lint
d-v-b 009f739
remove pedantic mode
d-v-b 7b26982
only run benchmarks in one environment
d-v-b c0342ee
use better string id for test params, make test data 1MB, and simplif…
d-v-b 800b64c
move layout to an external file
d-v-b f86291b
get workloads to resemble recent sharding perf tests
d-v-b dd76776
Merge branch 'main' of https://github.com/zarr-developers/zarr-python…
d-v-b 90502a6
test ids
d-v-b 5e0c228
Merge branch 'main' of https://github.com/zarr-developers/zarr-python…
d-v-b f613b29
tweak tests
d-v-b 602d79f
tweak tests
d-v-b 523f565
fix typo
d-v-b 9eb4bb6
add slice indexing benchmarks
d-v-b c9ab694
remove readme
d-v-b 0ecc190
add docs documentation
d-v-b b657e59
simplify pytest benchmark options
d-v-b 3033fbf
use --codspeed flag in benchmark ci
d-v-b 4394226
measure walltime in ci
d-v-b 7e4ca58
Merge branch 'main' into chore/benchmarks
d-v-b 27ca426
Merge branch 'main' into chore/benchmarks
d-v-b 93ea2e2
Update .github/workflows/codspeed.yml
d-v-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: CodSpeed Benchmarks | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| pull_request: | ||
| # `workflow_dispatch` allows CodSpeed to trigger backtest | ||
| # performance analysis in order to generate initial data. | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| benchmarks: | ||
| name: Run benchmarks | ||
| runs-on: codspeed-macro | ||
| 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: walltime | ||
| run: hatch run test.py3.11-1.26-minimal:pytest tests/benchmarks --codspeed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add continuous performance benchmarking infrastructure. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(kw_only=True, frozen=True) | ||
| class Layout: | ||
| shape: tuple[int, ...] | ||
| chunks: tuple[int, ...] | ||
| shards: tuple[int, ...] | None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """ | ||
| Benchmarks for end-to-end read/write performance of Zarr | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from tests.benchmarks.common import Layout | ||
|
|
||
| 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}}, | ||
| } | ||
|
|
||
|
|
||
| layouts: tuple[Layout, ...] = ( | ||
| # No shards, just 1000 chunks | ||
| Layout(shape=(1_000_000,), chunks=(1000,), shards=None), | ||
| # 1:1 chunk:shard shape, should measure overhead of sharding | ||
| Layout(shape=(1_000_000,), chunks=(1000,), shards=(1000,)), | ||
| # One shard with all the chunks, should measure overhead of handling inner shard chunks | ||
| Layout(shape=(1_000_000,), chunks=(100,), shards=(10000 * 100,)), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("compression_name", [None, "gzip"]) | ||
| @pytest.mark.parametrize("layout", layouts, ids=str) | ||
| @pytest.mark.parametrize("store", ["memory", "local"], 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, ids=str) | ||
| @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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pytest_benchmark.fixture import BenchmarkFixture | ||
|
|
||
| from zarr.abc.store import Store | ||
|
|
||
| from operator import getitem | ||
|
|
||
| import pytest | ||
|
|
||
| from zarr import create_array | ||
|
|
||
| indexers = ( | ||
| (0,) * 3, | ||
| (slice(None),) * 3, | ||
| (slice(0, None, 4),) * 3, | ||
| (slice(10),) * 3, | ||
| (slice(10, -10, 4),) * 3, | ||
| (slice(None), slice(0, 3, 2), slice(0, 10)), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("store", ["memory"], indirect=["store"]) | ||
| @pytest.mark.parametrize("indexer", indexers, ids=str) | ||
| def test_slice_indexing( | ||
| store: Store, indexer: tuple[int | slice], benchmark: BenchmarkFixture | ||
| ) -> None: | ||
| data = create_array( | ||
| store=store, | ||
| shape=(105,) * 3, | ||
| dtype="uint8", | ||
| chunks=(10,) * 3, | ||
| shards=None, | ||
| compressors=None, | ||
| filters=None, | ||
| fill_value=0, | ||
| ) | ||
|
|
||
| data[:] = 1 | ||
| benchmark(getitem, data, indexer) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.