From ac42799324c9159860af0931ff48bf5cc8299175 Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Fri, 12 Apr 2024 19:41:40 -0400 Subject: [PATCH] feat: add CodSpeed to the project --- .github/workflows/benchmark.yaml | 28 ++++++--------------- requirements/ci-3.11.txt | 43 +++++++++++--------------------- requirements/ci.in | 1 + tests/bench.py | 5 ++-- 4 files changed, 25 insertions(+), 52 deletions(-) diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index 98dc86ed92..fd789a6e91 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -3,6 +3,7 @@ on: push: branches: - main + pull_request: permissions: contents: write @@ -12,9 +13,6 @@ jobs: benchmark: name: Run pytest-benchmark runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10"] steps: - name: Checkout Code uses: actions/checkout@v4 @@ -23,27 +21,15 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.12 - name: Install requirements (Python 3) run: | - pip install -r requirements/ci.txt + pip install -r requirements/ci-3.11.txt - name: Install pypdf run: | pip install . - - name: Run benchmark - run: | - pytest tests/bench.py --benchmark-json output.json - - name: Store benchmark result - uses: benchmark-action/github-action-benchmark@v1 + - name: Run benchmarks + uses: CodSpeedHQ/action@v2 with: - name: Python Benchmark with pytest-benchmark - tool: 'pytest' - output-file-path: output.json - # Use personal access token instead of GITHUB_TOKEN due to https://github.community/t/github-action-not-triggering-gh-pages-upon-push/16096 - github-token: ${{ secrets.GITHUB_TOKEN }} - auto-push: true - # Show alert with commit comment on detecting possible performance regression - alert-threshold: '200%' - comment-on-alert: true - fail-on-alert: true - alert-comment-cc-users: '@MartinThoma' + token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest tests/bench.py --codspeed diff --git a/requirements/ci-3.11.txt b/requirements/ci-3.11.txt index f382fe2b94..7863b14595 100644 --- a/requirements/ci-3.11.txt +++ b/requirements/ci-3.11.txt @@ -1,34 +1,23 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile --config=pyproject.toml --output-file=requirements/ci-3.11.txt requirements/ci.in # -attrs==23.1.0 - # via flake8-bugbear +cffi==1.16.0 + # via pytest-codspeed coverage[toml]==7.3.0 # via # -r requirements/ci.in # pytest-cov execnet==2.0.2 # via pytest-xdist -flake8==6.1.0 - # via - # -r requirements/ci.in - # flake8-bugbear - # flake8-print -flake8-bugbear==23.7.10 - # via -r requirements/ci.in -flake8-implicit-str-concat==0.4.0 - # via -r requirements/ci.in -flake8-print==5.0.0 - # via -r requirements/ci.in +filelock==3.13.4 + # via pytest-codspeed fpdf2==2.4.1 # via -r requirements/ci.in iniconfig==2.0.0 # via pytest -mccabe==0.7.0 - # via flake8 mypy==1.5.1 # via -r requirements/ci.in mypy-extensions==1.0.0 @@ -43,24 +32,23 @@ pluggy==1.2.0 # via pytest py-cpuinfo==9.0.0 # via pytest-benchmark -pycodestyle==2.11.0 - # via - # flake8 - # flake8-print +pycparser==2.22 + # via cffi pycryptodome==3.18.0 # via -r requirements/ci.in -pyflakes==3.1.0 - # via flake8 pytest==7.4.0 # via # -r requirements/ci.in # pytest-benchmark + # pytest-codspeed # pytest-cov # pytest-socket # pytest-timeout # pytest-xdist pytest-benchmark==4.0.0 # via -r requirements/ci.in +pytest-codspeed==2.2.1 + # via -r requirements/ci.in pytest-cov==4.1.0 # via -r requirements/ci.in pytest-socket==0.6.0 @@ -71,15 +59,12 @@ pytest-xdist==3.3.1 # via -r requirements/ci.in pyyaml==6.0.1 # via -r requirements/ci.in -ruff==0.0.290 - # via -r requirements/ci.in typeguard==4.1.2 # via -r requirements/ci.in -types-dataclasses==0.6.6 - # via -r requirements/ci.in types-pillow==10.0.0.2 # via -r requirements/ci.in typing-extensions==4.7.1 - # via - # mypy - # typeguard + # via mypy + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/requirements/ci.in b/requirements/ci.in index a7f8bc7d68..3ce96c4ebf 100644 --- a/requirements/ci.in +++ b/requirements/ci.in @@ -5,6 +5,7 @@ pillow pycryptodome pytest pytest-benchmark +pytest-codspeed pytest-socket pytest-timeout pytest-xdist diff --git a/tests/bench.py b/tests/bench.py index dcfc30a9b9..6921b20627 100644 --- a/tests/bench.py +++ b/tests/bench.py @@ -142,7 +142,7 @@ def text_extraction(pdf_path): def test_text_extraction(benchmark): - file_path = SAMPLE_ROOT / "009-pdflatex-geotopo/GeoTopo.pdf" + file_path = SAMPLE_ROOT / "004-pdflatex-4-pages/pdflatex-4-pages.pdf" benchmark(text_extraction, file_path) @@ -201,7 +201,8 @@ def image_new_property(data): ["/TPL11", "/Image30"], ["/TPL12", "/Image30"], ] - assert len(reader.pages[0].images.items()) == 36 + # commented out to speed up the benchmark + # assert len(reader.pages[0].images.items()) == 36 assert reader.pages[0].images[0].name == "I0.png" assert len(reader.pages[0].images[-1].data) == 15168 assert reader.pages[0].images["/TPL1", "/Image5"].image.format == "JPEG"