From 26dbb0eddbe362df0d750a5470d491044176471b Mon Sep 17 00:00:00 2001 From: Jake <37048747+Jacob-Stevens-Haas@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:27:33 -0700 Subject: [PATCH] CI: Add Benchmarking --- .github/workflows/push-test.yml | 21 ++++++++++++- .gitignore | 8 +++++ asv_bench/asv.conf.json | 14 +++++++++ asv_bench/benchmarks/__init__.py | 0 asv_bench/benchmarks/finite_difference_1D.py | 31 ++++++++++++++++++++ pyproject.toml | 1 + 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 asv_bench/asv.conf.json create mode 100644 asv_bench/benchmarks/__init__.py create mode 100644 asv_bench/benchmarks/finite_difference_1D.py diff --git a/.github/workflows/push-test.yml b/.github/workflows/push-test.yml index 46696b7..7ef544d 100644 --- a/.github/workflows/push-test.yml +++ b/.github/workflows/push-test.yml @@ -57,4 +57,23 @@ jobs: # https://github.com/marketplace/actions/install-poetry-action#codecov-upload # ====== - name: Run tests - run: poetry run pytest \ No newline at end of file + run: poetry run pytest + + benchmarks: + name: ASV Benchmarks + needs: test + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Run ASV benchmarks + run: | + cd asv_bench + asv machine --yes + asv run --durations=30 --python=same --show-stderr \ No newline at end of file diff --git a/.gitignore b/.gitignore index 21ef3e1..6f84778 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,11 @@ venv.bak/ # Exploratory work playground/ + +# Unit / Performance Testing # +############################## +asv_bench/.asv/env/ +asv_bench/html/ +asv_bench/.asv/results/ +asv_bench/derivative/ +test-data.xml diff --git a/asv_bench/asv.conf.json b/asv_bench/asv.conf.json new file mode 100644 index 0000000..fcf0ca6 --- /dev/null +++ b/asv_bench/asv.conf.json @@ -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}" + ] +} diff --git a/asv_bench/benchmarks/__init__.py b/asv_bench/benchmarks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/asv_bench/benchmarks/finite_difference_1D.py b/asv_bench/benchmarks/finite_difference_1D.py new file mode 100644 index 0000000..6248a93 --- /dev/null +++ b/asv_bench/benchmarks/finite_difference_1D.py @@ -0,0 +1,31 @@ +# Write the benchmarking functions here. +# See "Writing benchmarks" in the asv docs for more information. + + +class TimeSuite: + """ + An example benchmark that times the performance of various kinds + of iterating over dictionaries in Python. + """ + def setup(self): + self.d = {} + for x in range(500): + self.d[x] = None + + def time_keys(self): + for key in self.d.keys(): + pass + + def time_values(self): + for value in self.d.values(): + pass + + def time_range(self): + d = self.d + for key in range(500): + d[key] + + +class MemSuite: + def mem_list(self): + return [0] * 256 diff --git a/pyproject.toml b/pyproject.toml index e582424..8d36613 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ 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]