diff --git a/tests/benchmarks/test_serialization_micro.py b/tests/benchmarks/test_serialization_micro.py index 96170b5eb..687c48a7e 100644 --- a/tests/benchmarks/test_serialization_micro.py +++ b/tests/benchmarks/test_serialization_micro.py @@ -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) @@ -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())