From 02309f7afe5aa9d9d42732490614becf608dd567 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 15 May 2024 16:04:27 -0400 Subject: [PATCH] benchmark performance of import (#653) Do a benchmark before working on #526 ## Summary by CodeRabbit - **New Features** - Introduced benchmark tests for import functionality and command line interface operations. - **Tests** - Added new benchmark tests to assess performance improvements. - **Chores** - Integrated `pytest` and `pytest-codspeed` into the project for enhanced testing capabilities. --------- Signed-off-by: Jinzhe Zeng Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/benchmark.yml | 23 +++++++++++++++++++++++ benchmark/__init__.py | 0 benchmark/test_import.py | 18 ++++++++++++++++++ pyproject.toml | 4 ++++ 4 files changed, 45 insertions(+) create mode 100644 .github/workflows/benchmark.yml create mode 100644 benchmark/__init__.py create mode 100644 benchmark/test_import.py diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 00000000..650ff59e --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,23 @@ +name: Python package + +on: + - push + - pull_request + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + - run: curl -LsSf https://astral.sh/uv/install.sh | sh + - name: Install dependencies + run: uv pip install --system .[amber,ase,pymatgen,benchmark] rdkit openbabel-wheel + - name: Run benchmarks + uses: CodSpeedHQ/action@v2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest benchmark/ --codspeed diff --git a/benchmark/__init__.py b/benchmark/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/benchmark/test_import.py b/benchmark/test_import.py new file mode 100644 index 00000000..04d46137 --- /dev/null +++ b/benchmark/test_import.py @@ -0,0 +1,18 @@ +import subprocess +import sys + +import pytest + + +@pytest.mark.benchmark +def test_import(): + """Test import dpdata.""" + subprocess.check_output( + [sys.executable, "-c", "'from dpdata import LabeledSystem'"] + ).decode("ascii") + + +@pytest.mark.benchmark +def test_cli(): + """Test dpdata command.""" + subprocess.check_output([sys.executable, "-m", "dpdata", "-h"]).decode("ascii") diff --git a/pyproject.toml b/pyproject.toml index 8ffec5ef..5292ba9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,10 @@ docs = [ 'jupyterlite-sphinx', 'jupyterlite-xeus', ] +benchmark = [ + 'pytest', + 'pytest-codspeed', +] [tool.setuptools.packages.find] include = ["dpdata*"]