-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add benchmarks for
get_for_dialect
(#1862)
- Loading branch information
Showing
5 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import asyncio | ||
|
||
from tests.testmodels import BenchmarkFewFields, DecimalFields | ||
from tortoise.expressions import F | ||
from tortoise.functions import Count | ||
|
||
|
||
def test_expressions_count(benchmark, few_fields_benchmark_dataset): | ||
loop = asyncio.get_event_loop() | ||
|
||
@benchmark | ||
def bench(): | ||
async def _bench(): | ||
await BenchmarkFewFields.annotate(text_count=Count("text")) | ||
|
||
loop.run_until_complete(_bench()) | ||
|
||
|
||
def test_expressions_f(benchmark, create_decimals): | ||
loop = asyncio.get_event_loop() | ||
|
||
@benchmark | ||
def bench(): | ||
async def _bench(): | ||
await DecimalFields.annotate(d=F("decimal")).all() | ||
|
||
loop.run_until_complete(_bench()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from tortoise.fields import Field | ||
|
||
|
||
class MyField(Field): | ||
@property | ||
def MY_PROPERTY(self): | ||
return f"hi from {self.__class__.__name__}!" | ||
|
||
OTHER_PROPERTY = "something else" | ||
|
||
class _db_property: | ||
def __init__(self, field: "Field"): | ||
self.field = field | ||
|
||
@property | ||
def MY_PROPERTY(self): | ||
return f"hi from {self.__class__.__name__} of {self.field.__class__.__name__}!" | ||
|
||
class _db_cls_attribute: | ||
MY_PROPERTY = "cls_attribute" | ||
|
||
|
||
def test_field_attribute_lookup_get_for_dialect(benchmark): | ||
field = MyField() | ||
|
||
@benchmark | ||
def bench(): | ||
field.get_for_dialect("property", "MY_PROPERTY") | ||
field.get_for_dialect("postgres", "MY_PROPERTY") | ||
field.get_for_dialect("cls_attribute", "MY_PROPERTY") | ||
field.get_for_dialect("property", "OTHER_PROPERTY") | ||
field.get_for_dialect("property", "MY_PROPERTY") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import asyncio | ||
|
||
from tests.testmodels import Event | ||
|
||
|
||
def test_relations_values_related_m2m(benchmark, create_team_with_participants): | ||
loop = asyncio.get_event_loop() | ||
|
||
@benchmark | ||
def bench(): | ||
async def _bench(): | ||
await Event.all().values("participants__name") | ||
|
||
loop.run_until_complete(_bench()) |