From 8030c5ae1cfb0517d333d5647ee66af8ab820440 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sun, 14 Jan 2024 21:38:48 +0000 Subject: [PATCH] add to_json ser benchmark --- tests/benchmarks/test_serialization_micro.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/test_serialization_micro.py b/tests/benchmarks/test_serialization_micro.py index 6a78de87a..9200fc24b 100644 --- a/tests/benchmarks/test_serialization_micro.py +++ b/tests/benchmarks/test_serialization_micro.py @@ -4,7 +4,7 @@ import pytest -from pydantic_core import SchemaSerializer, SchemaValidator, core_schema +from pydantic_core import SchemaSerializer, SchemaValidator, core_schema, to_json class TestBenchmarkSimpleModel: @@ -394,3 +394,18 @@ def test_filter(benchmark): @benchmark def t(): v.to_python(['a', 'b', 'c', 'd', 'e'], include={-1, -2}) + + +@pytest.mark.benchmark(group='list-of-lists') +def test_to_json_list_of_lists(benchmark): + data = [[i + j for j in range(10)] for i in range(1000)] + + benchmark(to_json, data) + + +@pytest.mark.benchmark(group='list-of-lists') +def test_ser_list_of_lists(benchmark): + s = SchemaSerializer(core_schema.list_schema(core_schema.list_schema(core_schema.int_schema()))) + data = [[i + j for j in range(10)] for i in range(1000)] + + benchmark(s.to_json, data)