Skip to content
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

CI: Add Benchmarking #46

Merged
merged 9 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion .github/workflows/push-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,68 @@ jobs:
# https://github.com/marketplace/actions/install-poetry-action#codecov-upload
# ======
- name: Run tests
run: poetry run pytest
run: poetry run pytest

benchmarks:
name: ASV Benchmarks
needs: test
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.9"]
poetry-version: ["1.2.1"]
steps:
# ======
# Checkout, set up python
# ======
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# ======
# Install and configure poetry
# ======
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.local # the path depends on the OS
key: poetry-${{ matrix.poetry-version }}
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: ${{ matrix.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
# ======
# Load cached venv if cache exists
# Install dependencies if cache does not exist
# ======
- name: Load cached venv
id: cached-poetry-dependencies-dev
uses: actions/cache@v4
with:
path: .venv
key: dev-${{ matrix.python-version }}-${{ matrix.poetry-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies-dev.outputs.cache-hit != 'true'
run: poetry install --no-interaction -E dev
# ======
# Compare benchmarks between master and PR, and fail if any get worse
# ======

- name: Setup ASV
run: |
pip install asv
cd asv_bench
asv machine --yes
- name: Check regression
run: |
cd asv_bench
git fetch origin $GITHUB_BASE_REF:base $GITHUB_REF:pr
asv continuous base pr -e
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ venv.bak/

# Exploratory work
playground/

# Unit / Performance Testing #
##############################
asv_bench/.asv/env/
asv_bench/.asv/html/
asv_bench/.asv/results/
asv_bench/derivative/
test-data.xml
14 changes: 14 additions & 0 deletions asv_bench/asv.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"project": "derivative",
"project_url": "https://derivative.readthedocs.io/",
"repo": "..",
"environment_type": "virtualenv",
"env_dir": ".asv/env",
"results_dir": ".asv/results",
"html_dir": ".asv/html",
"show_commit_url": "https://github.com/$OWNER/$REPO/commit/",
"build_command": [
"python -m build --outdir {build_cache_dir} {build_dir}"
]
}
Empty file.
19 changes: 19 additions & 0 deletions asv_bench/benchmarks/finite_difference_1D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Write the benchmarking functions here.
# See "Writing benchmarks" in the asv docs for more information.
import numpy as np
from derivative import FiniteDifference

class FiniteDifferenceBM:
"""
An example benchmark that times the performance of various kinds
of iterating over dictionaries in Python.
"""
def setup(self):
self.differentiator = FiniteDifference(k=1)
self.t = np.arange(0, 2 * np.pi, .01)

def time_derivative(self):
self.differentiator.d(X=self.t, t=self.t, axis=0)

def peakmem_derivative(self):
self.differentiator.d(X=self.t, t=self.t, axis=0)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ matplotlib = {version = "^3.2.1", optional = true}
#pandoc = {version = "^2.2", optional = true}

# dev
asv = {version = "^0.6", optional = true}
pytest = {version = "^7", optional = true}

[tool.poetry.extras]
docs = ["sphinx", "nbsphinx", "ipykernel", "jupyter_client", "matplotlib", "pandoc"]
dev = ["pytest"]
dev = ["asv", "pytest"]

[build-system]
requires = ["poetry-core>=1.1.0"]
Expand Down
Loading