Skip to content

Commit

Permalink
add to_json ser benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jan 14, 2024
1 parent 700e17d commit 8030c5a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/benchmarks/test_serialization_micro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit 8030c5a

Please sign in to comment.