-
Notifications
You must be signed in to change notification settings - Fork 127
Add performance benchmarks #748
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
Merged
gadomski
merged 25 commits into
stac-utils:main
from
duckontheweb:add/729-performance-benchmarks
Jan 11, 2023
Merged
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ca0a6fa
Configure asv and add import benchmark
duckontheweb 67633b2
Add item (de)serialization benchmarks & use 10 reps
duckontheweb ed65815
Add catalog, collection benchmarks and tweak settings
duckontheweb 3f5bb3d
Add convenience script for running locally
duckontheweb 78d97f5
Use default Python
duckontheweb db7e92d
Add benchmark workflow to CI
duckontheweb c187569
Match label condition to label name in repo
duckontheweb d6440b0
Fix lint errors
duckontheweb 01798fc
Add virtualenv to benchmark deps
duckontheweb 8648b23
Fix artifact name, increase failure threshold
duckontheweb c0267bb
Merge branch 'main' into add/729-performance-benchmarks
gadomski 6a00081
rm: benchmarks workflow
gadomski 6a35b1e
refactor: use classes directly
gadomski 0f574d8
refactor: move benchmarks up a level
gadomski 1afea50
feat: add projection benchmarks
gadomski 65155a4
feat: add large catalog benchmarks
gadomski 3767735
fix: benchmark config
gadomski 06ec7b8
feat: add benchmark docs
gadomski 1ed23a8
ci: add benchmark check
gadomski 12a08b5
ci: set the asv machine
gadomski 34c4369
ci: install pystac for benchmarks
gadomski 5b39551
Merge branch 'main' into add/729-performance-benchmarks
gadomski a170df5
docs: add more text about running benchmarks
gadomski 3b09da4
bench: use timeraw for import
gadomski e023b4f
Merge branch 'main' into add/729-performance-benchmarks
gadomski 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
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 |
|---|---|---|
|
|
@@ -157,3 +157,6 @@ dmypy.json | |
|
|
||
| # Cython debug symbols | ||
| cython_debug/ | ||
|
|
||
| # asv environments | ||
| .asv | ||
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,24 @@ | ||
| { | ||
| "version": 1, | ||
| "project": "pystac", | ||
| "project_url": "https://pystac.readthedocs.io/", | ||
| "repo": ".", | ||
| "branches": [ | ||
| "main" | ||
| ], | ||
| "dvcs": "git", | ||
| "environment_type": "virtualenv", | ||
| "show_commit_url": "http://github.com/stac-utils/pystac/commit/", | ||
| "matrix": { | ||
| "req": { | ||
| "orjson": [ | ||
| null, | ||
| "" | ||
| ] | ||
| } | ||
| }, | ||
| "benchmark_dir": "benchmarks", | ||
| "env_dir": ".asv/env", | ||
| "results_dir": ".asv/results", | ||
| "html_dir": ".asv/html" | ||
| } |
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,6 @@ | ||
| class Bench: | ||
| # Repeat between 10-50 times up to a max time of 5s | ||
| repeat = (10, 50, 2.0) | ||
|
|
||
| # Bump number of rounds to 4 | ||
| rounds = 4 |
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,16 @@ | ||
| import os | ||
| from typing import Union, TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| PathLike = os.PathLike[str] | ||
| else: | ||
| PathLike = os.PathLike | ||
|
|
||
|
|
||
| def get_data_path(rel_path: Union[str, PathLike]) -> str: | ||
| """Gets the absolute path to a file based on a path relative to the | ||
| tests/data-files directory in this repo.""" | ||
| rel_path = os.fspath(rel_path) | ||
| return os.path.abspath( | ||
| os.path.join(os.path.dirname(__file__), "..", "tests", "data-files", rel_path) | ||
| ) |
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,118 @@ | ||
| import datetime | ||
| import json | ||
| import os | ||
| import shutil | ||
| import tempfile | ||
| from pathlib import Path | ||
| from tempfile import TemporaryDirectory | ||
| from pystac import ( | ||
| Catalog, | ||
| StacIO, | ||
| Collection, | ||
| Extent, | ||
| TemporalExtent, | ||
| SpatialExtent, | ||
| Item, | ||
| ) | ||
|
|
||
| from ._base import Bench | ||
| from ._util import get_data_path | ||
|
|
||
|
|
||
| class CatalogBench(Bench): | ||
| def setup(self) -> None: | ||
| self.temp_dir = tempfile.mkdtemp() | ||
|
|
||
| self.stac_io = StacIO.default() | ||
|
|
||
| self.catalog_path = get_data_path("examples/1.0.0/catalog.json") | ||
| with open(self.catalog_path) as src: | ||
| self.catalog_dict = json.load(src) | ||
| self.catalog = Catalog.from_file(self.catalog_path) | ||
|
|
||
| def teardown(self) -> None: | ||
| shutil.rmtree(self.temp_dir, ignore_errors=True) | ||
|
|
||
| def time_catalog_from_file(self) -> None: | ||
| """Deserialize an Item from file""" | ||
| _ = Catalog.from_file(self.catalog_path) | ||
|
|
||
| def time_catalog_from_dict(self) -> None: | ||
| """Deserialize an Item from dictionary.""" | ||
| _ = Catalog.from_dict(self.catalog_dict) | ||
|
|
||
| def time_catalog_to_dict(self) -> None: | ||
| """Serialize an Item to a dictionary.""" | ||
| self.catalog.to_dict(include_self_link=True) | ||
|
|
||
| def time_catalog_save(self) -> None: | ||
| """Serialize an Item to a JSON file.""" | ||
| self.catalog.save_object( | ||
| include_self_link=True, | ||
| dest_href=os.path.join(self.temp_dir, "time_catalog_save.json"), | ||
| stac_io=self.stac_io, | ||
| ) | ||
|
|
||
|
|
||
| class WalkCatalogBench(Bench): | ||
| def setup_cache(self) -> Catalog: | ||
| return make_large_catalog() | ||
|
|
||
| def time_walk(self, catalog: Catalog) -> None: | ||
| for ( | ||
| _, | ||
| _, | ||
| _, | ||
| ) in catalog.walk(): | ||
| pass | ||
|
|
||
| def peakmem_walk(self, catalog: Catalog) -> None: | ||
| for ( | ||
| _, | ||
| _, | ||
| _, | ||
| ) in catalog.walk(): | ||
| pass | ||
|
|
||
|
|
||
| class ReadCatalogBench(Bench): | ||
| def setup(self) -> None: | ||
| catalog = make_large_catalog() | ||
| self.temporary_directory = TemporaryDirectory() | ||
| self.path = str(Path(self.temporary_directory.name) / "catalog.json") | ||
| catalog.normalize_and_save(self.temporary_directory.name) | ||
|
|
||
| def teardown(self) -> None: | ||
| shutil.rmtree(self.temporary_directory.name) | ||
|
|
||
| def time_read_and_walk(self) -> None: | ||
| catalog = Catalog.from_file(self.path) | ||
| for _, _, _ in catalog.walk(): | ||
| pass | ||
|
|
||
|
|
||
| class WriteCatalogBench(Bench): | ||
| def setup(self) -> None: | ||
| self.catalog = make_large_catalog() | ||
| self.temporary_directory = TemporaryDirectory() | ||
|
|
||
| def teardown(self) -> None: | ||
| shutil.rmtree(self.temporary_directory.name) | ||
|
|
||
| def time_normalize_and_save(self) -> None: | ||
| self.catalog.normalize_and_save(self.temporary_directory.name) | ||
|
|
||
|
|
||
| def make_large_catalog() -> Catalog: | ||
| catalog = Catalog("an-id", "a description") | ||
| extent = Extent( | ||
| SpatialExtent([[-180.0, -90.0, 180.0, 90.0]]), | ||
| TemporalExtent([[datetime.datetime(2023, 1, 1), None]]), | ||
| ) | ||
| for i in range(0, 10): | ||
| collection = Collection(f"collection-{i}", f"Collection {i}", extent) | ||
| for j in range(0, 100): | ||
| item = Item(f"item-{i}-{j}", None, None, datetime.datetime.now(), {}) | ||
| collection.add_item(item) | ||
| catalog.add_child(collection) | ||
| return catalog |
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 @@ | ||
| import json | ||
| import os | ||
| import shutil | ||
| import tempfile | ||
| from pystac import StacIO, Collection | ||
|
|
||
| from ._base import Bench | ||
| from ._util import get_data_path | ||
|
|
||
|
|
||
| class CollectionBench(Bench): | ||
| def setup(self) -> None: | ||
| self.temp_dir = tempfile.mkdtemp() | ||
|
|
||
| self.stac_io = StacIO.default() | ||
|
|
||
| self.collection_path = get_data_path("examples/1.0.0/collection.json") | ||
| with open(self.collection_path) as src: | ||
| self.collection_dict = json.load(src) | ||
| self.collection = Collection.from_file(self.collection_path) | ||
|
|
||
| def teardown(self) -> None: | ||
| shutil.rmtree(self.temp_dir, ignore_errors=True) | ||
|
|
||
| def time_collection_from_file(self) -> None: | ||
| """Deserialize an Item from file""" | ||
| _ = Collection.from_file(self.collection_path) | ||
|
|
||
| def time_collection_from_dict(self) -> None: | ||
| """Deserialize an Item from dictionary.""" | ||
| _ = Collection.from_dict(self.collection_dict) | ||
|
|
||
| def time_collection_to_dict(self) -> None: | ||
| """Serialize an Item to a dictionary.""" | ||
| self.collection.to_dict(include_self_link=True) | ||
|
|
||
| def time_collection_save(self) -> None: | ||
| """Serialize an Item to a JSON file.""" | ||
| self.collection.save_object( | ||
| include_self_link=True, | ||
| dest_href=os.path.join(self.temp_dir, "time_collection_save.json"), | ||
| stac_io=self.stac_io, | ||
| ) |
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,14 @@ | ||
| import datetime | ||
|
|
||
| from pystac import Item | ||
| from pystac.extensions.projection import ProjectionExtension | ||
|
|
||
| from .._base import Bench | ||
|
|
||
|
|
||
| class ProjectionBench(Bench): | ||
| def setup(self) -> None: | ||
| self.item = Item("an-id", None, None, datetime.datetime.now(), {}) | ||
|
|
||
| def time_add_projection_extension(self) -> None: | ||
| _ = ProjectionExtension.ext(self.item, add_if_missing=True) |
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,14 @@ | ||
| from typing import Any | ||
|
|
||
|
|
||
| class ImportPySTACBench: | ||
| repeat = 10 | ||
|
|
||
| def setup(self, *args: Any, **kwargs: Any) -> None: | ||
| def import_pystac() -> None: | ||
| import pystac # noqa: F401 | ||
|
|
||
| self._import_pystac = import_pystac | ||
|
|
||
| def time_import_pystac(self) -> None: | ||
| self._import_pystac() | ||
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 @@ | ||
| import json | ||
| import os | ||
| import shutil | ||
| import tempfile | ||
| from pystac import StacIO, Item | ||
|
|
||
| from ._base import Bench | ||
| from ._util import get_data_path | ||
|
|
||
|
|
||
| class ItemBench(Bench): | ||
| def setup(self) -> None: | ||
| self.temp_dir = tempfile.mkdtemp() | ||
|
|
||
| self.stac_io = StacIO.default() | ||
|
|
||
| self.item_path = get_data_path("item/sample-item-asset-properties.json") | ||
| with open(self.item_path) as src: | ||
| self.item_dict = json.load(src) | ||
| self.item = Item.from_file(self.item_path) | ||
|
|
||
| def teardown(self) -> None: | ||
| shutil.rmtree(self.temp_dir, ignore_errors=True) | ||
|
|
||
| def time_item_from_file(self) -> None: | ||
| """Deserialize an Item from file""" | ||
| _ = Item.from_file(self.item_path) | ||
|
|
||
| def time_item_from_dict(self) -> None: | ||
| """Deserialize an Item from dictionary.""" | ||
| _ = Item.from_dict(self.item_dict) | ||
|
|
||
| def time_item_to_dict(self) -> None: | ||
| """Serialize an Item to a dictionary.""" | ||
| self.item.to_dict(include_self_link=True) | ||
|
|
||
| def time_item_save(self) -> None: | ||
| """Serialize an Item to a JSON file.""" | ||
| self.item.save_object( | ||
| include_self_link=True, | ||
| dest_href=os.path.join(self.temp_dir, "time_item_save.json"), | ||
| stac_io=self.stac_io, | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| asv==0.5.1 | ||
| virtualenv==20.13.1 |
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| -r ./requirements-docs.txt | ||
| -r ./requirements-test.txt | ||
| -r ./requirements-bench.txt | ||
|
|
||
| jupyter==1.0.0 |
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,11 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| if [[ -z $ASV_FACTOR ]]; then | ||
| ASV_FACTOR=1.25; | ||
| fi | ||
|
|
||
| asv continuous --split -e --interleave-rounds \ | ||
| --factor ${ASV_FACTOR} \ | ||
| main HEAD; |
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.