Skip to content

Commit

Permalink
fix benchmarks, add codspeed instead of pytest-benchmark, add action …
Browse files Browse the repository at this point in the history
…and gh workflow
  • Loading branch information
collerek committed Feb 7, 2024
1 parent ab85c81 commit 80a93b4
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 386 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: codspeed-benchmarks

on:
push:
branches:
- "master" # or "master"
pull_request:
branches: [ master, pydantic_v2 ]
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.11"

- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.4.2
virtualenvs-create: false

- name: Poetry details
run: |
poetry --version
poetry config --list
- name: Install dependencies
run: poetry install --extras "all"

- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: poetry run pytest benchmarks/ --codspeed
2 changes: 1 addition & 1 deletion benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def authors_in_db(num_models: int):
authors = [
Author(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
score=int(random.random() * 100),
)
for i in range(0, num_models)
]
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_benchmark_bulk_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def make_and_insert(num_models: int):
authors = [
Author(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
score=int(random.random() * 100),
)
for i in range(0, num_models)
]
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/test_benchmark_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def create(num_models: int):
for idx in range(0, num_models):
author = await Author.objects.create(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
score=int(random.random() * 100),
)
authors.append(author)
return authors
Expand Down Expand Up @@ -62,7 +62,7 @@ async def get_or_create(num_models: int):
for idx in range(0, num_models):
author, created = await Author.objects.get_or_create(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
score=int(random.random() * 100),
)
assert created
authors.append(author)
Expand All @@ -81,7 +81,7 @@ async def update_or_create(num_models: int):
for idx in range(0, num_models):
author = await Author.objects.update_or_create(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
score=int(random.random() * 100),
)
authors.append(author)
return authors
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/test_benchmark_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ async def initialize_models(num_models: int):
authors = [
Author(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
score=int(random.random() * 100),
)
for i in range(0, num_models)
]
assert len(authors) == num_models

await initialize_models(num_models)
_ = initialize_models(num_models)


@pytest.mark.parametrize("num_models", [10, 20, 40])
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_benchmark_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def make_and_insert(num_models: int):
authors = [
Author(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
score=int(random.random() * 100),
)
for i in range(0, num_models)
]
Expand Down
733 changes: 356 additions & 377 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ dataclasses = { version = ">=0.6.0,<0.8 || >0.8,<1.0.0" }

# Performance testing
yappi = "^1.4.0"
pytest-benchmark = "^4.0.0"
nest-asyncio = "^1.5.6"

pre-commit = "^2.21.0"
httpx = "^0.24.1"
asgi-lifespan = "^2.1.0"
pydantic-extra-types = "^2.5.0"
pytest-codspeed = "^2.2.0"


[build-system]
Expand Down

0 comments on commit 80a93b4

Please sign in to comment.