Skip to content

Commit c61b76c

Browse files
committed
Add filter benchmark
1 parent 25b6ca7 commit c61b76c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

tests/benchmarks/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
from decimal import Decimal
35
import random
@@ -17,13 +19,13 @@ def setup_database():
1719

1820
@pytest.fixture(scope="module", autouse=True)
1921
def skip_if_codspeed_not_enabled(request):
20-
if not request.config.getoption("--codspeed"):
21-
pytest.skip("codspeed tests are disabled")
22+
if not request.config.getoption("--codspeed", default=None):
23+
pytest.skip("codspeed is not enabled")
2224

2325

2426
@pytest.fixture
2527
def few_fields_benchmark_dataset() -> list[BenchmarkFewFields]:
26-
async def _create():
28+
async def _create() -> list[BenchmarkFewFields]:
2729
res = []
2830
for _ in range(100):
2931
res.append(await BenchmarkFewFields.create(level=random.randint(0, 100), text="test"))
@@ -34,7 +36,7 @@ async def _create():
3436

3537
@pytest.fixture
3638
def many_fields_benchmark_dataset() -> list[BenchmarkManyFields]:
37-
async def _create():
39+
async def _create() -> list[BenchmarkManyFields]:
3840
res = []
3941
for _ in range(100):
4042
res.append(

tests/benchmarks/test_filter.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import asyncio
2+
import random
3+
4+
from tests.testmodels import BenchmarkFewFields
5+
6+
7+
def test_filter_few_fields(benchmark, few_fields_benchmark_dataset):
8+
loop = asyncio.get_event_loop()
9+
levels = list(set([o.level for o in few_fields_benchmark_dataset]))
10+
11+
@benchmark
12+
def bench():
13+
async def _bench():
14+
await BenchmarkFewFields.filter(level__in=random.sample(levels, 5)).limit(5)
15+
16+
loop.run_until_complete(_bench())

0 commit comments

Comments
 (0)