Skip to content

Commit 52d58d2

Browse files
authored
Add set benchmarks with duplicates (#606)
1 parent 3603f10 commit 52d58d2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/benchmarks/test_micro_benchmarks.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ def t():
476476

477477

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

480481

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

502503

504+
@pytest.mark.benchmark(group='Set[int]')
505+
def test_set_of_ints_core_duplicates(benchmark):
506+
v = SchemaValidator({'type': 'set', 'items_schema': {'type': 'int'}})
507+
508+
@benchmark
509+
def t():
510+
v.validate_python(set_of_ints_duplicates[0])
511+
v.validate_python(set_of_ints_duplicates[1])
512+
513+
503514
@skip_pydantic
504515
@pytest.mark.benchmark(group='Set[int] JSON')
505516
def test_set_of_ints_pyd_json(benchmark):
@@ -518,6 +529,18 @@ def t():
518529
def test_set_of_ints_core_json(benchmark):
519530
v = SchemaValidator({'type': 'set', 'items_schema': {'type': 'int'}})
520531

532+
json_data = [json.dumps(list(d)) for d in set_of_ints_duplicates]
533+
534+
@benchmark
535+
def t():
536+
v.validate_json(json_data[0])
537+
v.validate_json(json_data[1])
538+
539+
540+
@pytest.mark.benchmark(group='Set[int] JSON')
541+
def test_set_of_ints_core_json_duplicates(benchmark):
542+
v = SchemaValidator({'type': 'set', 'items_schema': {'type': 'int'}})
543+
521544
json_data = [json.dumps(list(d)) for d in set_of_ints_data]
522545

523546
@benchmark
@@ -527,6 +550,7 @@ def t():
527550

528551

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

531555

532556
@skip_pydantic
@@ -545,6 +569,13 @@ def test_frozenset_of_ints_core(benchmark):
545569
benchmark(v.validate_python, frozenset_of_ints)
546570

547571

572+
@pytest.mark.benchmark(group='FrozenSet[int]')
573+
def test_frozenset_of_ints_duplicates_core(benchmark):
574+
v = SchemaValidator({'type': 'frozenset', 'items_schema': {'type': 'int'}})
575+
576+
benchmark(v.validate_python, frozenset_of_ints_duplicates)
577+
578+
548579
dict_of_ints_data = ({str(i): i for i in range(1000)}, {str(i): str(i) for i in range(1000)})
549580

550581

0 commit comments

Comments
 (0)