Skip to content

Commit

Permalink
chore: make benchmarks runnable in CI (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jul 29, 2024
1 parent 7a68c25 commit daac28d
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 49 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,42 @@ jobs:
fi
shell: bash
- name: Test with Pytest
run: poetry run pytest --cov-report=xml
run: poetry run pytest --cov-report=xml -v -Wdefault --cov=bluetooth_data_tools --cov-report=term-missing:skip-covered tests
shell: bash
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

benchmark:
strategy:
fail-fast: false
matrix:
python-version:
- "3.12"
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: snok/install-poetry@v1.3.3
- name: Install Dependencies
run: poetry install --only=main,dev,benchmark
env:
REQUIRE_CYTHON: 1
- name: Run benchmarks
run: |
poetry run pytest bench --benchmark-autosave
echo '# Benchmark Results' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
poetry run pytest-benchmark compare --columns=mean,ops >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
shell: bash

release:
runs-on: ubuntu-latest
environment: release
Expand Down
Empty file added bench/__init__.py
Empty file.
21 changes: 0 additions & 21 deletions bench/int_to_bluetooth_address.py

This file was deleted.

12 changes: 12 additions & 0 deletions bench/test_int_to_bluetooth_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from bluetooth_data_tools.utils import (
_int_to_bluetooth_address,
int_to_bluetooth_address,
)


def test_parse_int_to_bluetooth_address_uncached(benchmark):
benchmark(lambda: _int_to_bluetooth_address(0))


def test_parse_int_to_bluetooth_address_cached(benchmark):
benchmark(lambda: int_to_bluetooth_address(0))
11 changes: 2 additions & 9 deletions bench/parse_gap.py → bench/test_parse_gap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import timeit

from bluetooth_data_tools import parse_advertisement_data

# cythonize -X language_level=3 -a -i src/bluetooth_data_tools/gap.py
Expand Down Expand Up @@ -83,10 +81,5 @@
]


def parse_adv() -> None:
parse_advertisement_data(advs)


count = 100000
time = timeit.Timer(parse_adv).timeit(count)
print(f"Parsing {count} bluetooth messages took {time} seconds")
def test_parse_advertisement_data(benchmark):
benchmark(lambda: parse_advertisement_data(advs))
19 changes: 4 additions & 15 deletions bench/parse_gap_tuple.py → bench/test_parse_gap_tuple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import timeit

from bluetooth_data_tools import parse_advertisement_data_tuple
from bluetooth_data_tools.gap import _uncached_parse_advertisement_data

Expand Down Expand Up @@ -84,18 +82,9 @@
)


def parse_adv() -> None:
parse_advertisement_data_tuple(advs)


count = 100000
time = timeit.Timer(parse_adv).timeit(count)
print(f"Parsing {count} bluetooth messages took {time} seconds")


def uncached_parse_adv() -> None:
_uncached_parse_advertisement_data(advs)
def test_parse_advertisement_data_tuple(benchmark):
benchmark(lambda: parse_advertisement_data_tuple(advs))


time = timeit.Timer(uncached_parse_adv).timeit(count)
print(f"Parsing {count} bluetooth messages without caching took {time} seconds")
def test_parse_advertisement_data_tuple_uncached(benchmark):
benchmark(lambda: _uncached_parse_advertisement_data(advs))
35 changes: 33 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ docs = [
pytest = "^7.0"
pytest-cov = "^3.0"

[tool.poetry.group.benchmark.dependencies]
pytest-benchmark = "^4.0.0"

[tool.semantic_release]
branch = "main"
version_toml = "pyproject.toml:tool.poetry.version"
version_variable = "src/bluetooth_data_tools/__init__.py:__version__"
build_command = "pip install poetry && poetry build"

[tool.pytest.ini_options]
addopts = "-v -Wdefault --cov=bluetooth_data_tools --cov-report=term-missing:skip-covered"
pythonpath = ["src"]

[tool.coverage.run]
Expand Down Expand Up @@ -86,6 +88,10 @@ exclude = [
module = "tests.*"
allow_untyped_defs = true

[[tool.mypy.overrides]]
module = "bench.*"
allow_untyped_defs = true

[[tool.mypy.overrides]]
module = "docs.*"
ignore_errors = true
Expand Down

0 comments on commit daac28d

Please sign in to comment.