8000 Add set benchmarks with duplicates by adriangb · Pull Request #606 · pydantic/pydantic-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add set benchmarks with duplicates #606

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

Merged
merged 1 commit into from
May 16, 2023
Merged
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions tests/benchmarks/test_micro_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ def t():


set_of_ints_data = ({i for i in range(1000)}, {str(i) for i in range(1000)})
set_of_ints_duplicates = ([i for i in range(100)] * 10, [str(i) for i in range(100)] * 10)


@skip_pydantic
Expand All @@ -500,6 +501,16 @@ def t():
v.validate_python(set_of_ints_data[1])


@pytest.mark.benchmark(group='Set[int]')
def test_set_of_ints_core_duplicates(benchmark):
v = SchemaValidator({'type': 'set', 'items_schema': {'type': 'int'}})

@benchmark
def t():
v.validate_python(set_of_ints_duplicates[0])
v.validate_python(set_of_ints_duplicates[1])


@skip_pydantic
@pytest.mark.benchmark(group='Set[int] JSON')
def test_set_of_ints_pyd_json(benchmark):
Expand All @@ -518,6 +529,18 @@ def t():
def test_set_of_ints_core_json(benchmark):
v = SchemaValidator({'type': 'set', 'items_schema': {'type': 'int'}})

json_data = [json.dumps(list(d)) for d in set_of_ints_duplicates]

@benchmark
def t():
v.validate_json(json_data[0])
v.validate_json(json_data[1])


@pytest.mark.benchmark(group='Set[int] JSON')
def test_set_of_ints_core_json_duplicates(benchmark):
v = SchemaValidator({'type': 'set', 'items_schema': {'type': 'int'}})

json_data = [json.dumps(list(d)) for d in set_of_ints_data]

@benchmark
Expand All @@ -527,6 +550,7 @@ def t():


frozenset_of_ints = frozenset({i for i in range(1000)})
frozenset_of_ints_duplicates = [i for i in range(100)] * 10


@skip_pydantic
Expand All @@ -545,6 +569,13 @@ def test_frozenset_of_ints_core(benchmark):
benchmark(v.validate_python, frozenset_of_ints)


@pytest.mark.benchmark(group='FrozenSet[int]')
def test_frozenset_of_ints_duplicates_core(benchmark):
v = SchemaValidator({'type': 'frozenset', 'items_schema': {'type': 'int'}})

benchmark(v.validate_python, frozenset_of_ints_duplicates)


dict_of_ints_data = ({str(i): i for i in range(1000)}, {str(i): str(i) for i in range(1000)})


Expand Down
0