Skip to content

Benchmarks for perf #1756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion tests/benchmarks/test_serialization_micro.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def r():
s.to_json(m_big)


@pytest.mark.benchmark(group='model-list-json')
@pytest.mark.benchmark(group='temporal')
def test_datetime(benchmark):
v = SchemaSerializer(core_schema.datetime_schema())
d = datetime(2022, 12, 2, 12, 13, 14)
Expand All @@ -360,6 +360,33 @@ def r():
v.to_python(d, mode='json')


@pytest.mark.benchmark(group='temporal')
def test_datetime_seconds(benchmark):
v = SchemaSerializer(
core_schema.datetime_schema(),
config={
'ser_json_temporal': 'seconds',
},
)
d = datetime(2022, 12, 2, 12, 13, 14)
assert v.to_python(d, mode='json') == 1669983194.0

@benchmark
def r():
v.to_python(d, mode='json')


@pytest.mark.benchmark(group='temporal')
def test_datetime_milliseconds(benchmark):
v = SchemaSerializer(core_schema.datetime_schema(), config={'ser_json_temporal': 'milliseconds'})
d = datetime(2022, 12, 2, 12, 13, 14)
assert v.to_python(d, mode='json') == 1669983194000.0

@benchmark
def r():
v.to_python(d, mode='json')


@pytest.mark.benchmark(group='model-list-json')
def test_uuid(benchmark):
v = SchemaSerializer(core_schema.uuid_schema())
Expand Down
Loading