Skip to content
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

Add some other fields to Benchmarks, Add Multi Dialect support to a benchmark, Improve Benchmark Output & simplify filtering benchmarks by tags #1425

Merged
merged 16 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
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
486 changes: 300 additions & 186 deletions bowtie/_benchmarks.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion bowtie/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,11 +1442,13 @@ def filter_benchmarks(
"""
Output benchmarks matching the specified criteria.
"""
_benchmarks.get_benchmark_filenames(
files: list[Path] = _benchmarks.get_benchmark_files(
benchmark_type,
benchmarks=benchmark_names,
dialect=dialect,
)
for file in files:
console.Console().file.write(f"{file}\n")


LANGUAGE_ALIASES = {
Expand Down
49 changes: 34 additions & 15 deletions bowtie/benchmarks/contains.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from bowtie._benchmarks import Benchmark
from pathlib import Path

from url.url import URL

from bowtie._benchmarks import BenchmarkGroup
from bowtie._core import Dialect


def get_benchmark():
Expand All @@ -8,18 +13,32 @@ def get_benchmark():
end = [0] * (array_size - 1) + [37]
invalid = [0] * array_size

return Benchmark.from_dict(
name="contains",
description="A benchmark for validation of the `contains` keyword.",
schema={
"type": "array",
"contains": {"const": 37},
},
tests=[
dict(description="Empty array", instance=[]),
dict(description="Beginning of array", instance=beginning),
dict(description="Middle of array", instance=middle),
dict(description="End of array", instance=end),
dict(description="Invalid array", instance=invalid),
],
return BenchmarkGroup.from_dict(
data=dict(
name="contains",
benchmark_type="default",
dialects_supported=[
Dialect.from_str(
"https://json-schema.org/draft/2020-12/schema",
),
Dialect.from_str(
"https://json-schema.org/draft/2019-09/schema",
),
Dialect.from_str("http://json-schema.org/draft-07/schema#"),
Dialect.from_str("http://json-schema.org/draft-06/schema#"),
],
description="A benchmark for validation of the `contains` keyword.",
schema={
"type": "array",
"contains": {"const": 37},
},
tests=[
dict(description="Empty array", instance=[]),
dict(description="Beginning of array", instance=beginning),
dict(description="Middle of array", instance=middle),
dict(description="End of array", instance=end),
dict(description="Invalid array", instance=invalid),
],
),
uri=URL.parse(Path(__file__).absolute().as_uri()),
)
39 changes: 26 additions & 13 deletions bowtie/benchmarks/draft2020_metaschema.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
from pathlib import Path

from jsonschema_specifications import REGISTRY as SPECIFICATIONS
from url.url import URL

from bowtie._benchmarks import Benchmark
from bowtie._benchmarks import BenchmarkGroup
from bowtie._core import Dialect

DRAFT202012_DIALECT_URI = "https://json-schema.org/draft/2020-12/schema"


def get_benchmark():
return Benchmark.from_dict(
name="Draft2020-12_MetaSchema",
description=(
"A benchmark for validation of the Draft2020-12 MetaSchema."
),
schema=SPECIFICATIONS.contents(DRAFT202012_DIALECT_URI),
tests=[
dict(
description="Validating metaschema against metaschema",
instance=SPECIFICATIONS.contents(
DRAFT202012_DIALECT_URI,
return BenchmarkGroup.from_dict(
data=dict(
name="Draft2020-12_MetaSchema",
benchmark_type="default",
dialects_supported=[
Dialect.from_str(
"https://json-schema.org/draft/2020-12/schema",
),
],
description=(
"A benchmark for validation of the Draft2020-12 MetaSchema."
),
],
schema=SPECIFICATIONS.contents(DRAFT202012_DIALECT_URI),
tests=[
dict(
description="Validating metaschema against metaschema",
instance=SPECIFICATIONS.contents(
DRAFT202012_DIALECT_URI,
),
),
],
),
uri=URL.parse(Path(__file__).absolute().as_uri()),
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
from url.url import URL

from bowtie._benchmarks import Benchmark, BenchmarkGroup
from bowtie._core import Dialect


def get_benchmark():
name = "additionalProperties"
benchmark_type = "keyword"
description = (
"A benchmark for measuring performance of the "
"implementation for the additionalProperties keyword."
)
max_array_size = 100000
benchmarks: list[Benchmark] = []

array_size = 1000
max_array_length = 100000
varying_parameter = "Array length"

while array_size <= max_array_size:
array_length = 1000
benchmarks: list[Benchmark] = []
while array_length <= max_array_length:
allowed_properties = [
uuid.uuid4().hex for _ in range(max_array_size - 1)
uuid.uuid4().hex for _ in range(max_array_length - 1)
]

middle_index = len(allowed_properties) // 2
Expand Down Expand Up @@ -57,7 +59,7 @@ def get_benchmark():
instance=_format_properties_as_instance(valid),
),
]
if array_size == max_array_size
if array_length == max_array_length
else [
dict(
description="Valid",
Expand All @@ -68,9 +70,9 @@ def get_benchmark():

benchmarks.append(
Benchmark.from_dict(
name=f"Array Size - {array_size}",
name=f"Array length - {array_length}",
description=(
f"Validating additionalProperties keyword over array of size {array_size}"
f"Validating additionalProperties keyword over array of length {array_length}"
),
schema=dict(
properties={key: {} for key in allowed_properties},
Expand All @@ -80,12 +82,22 @@ def get_benchmark():
),
)

array_size *= 10
array_length *= 10

return BenchmarkGroup(
name=name,
benchmark_type=benchmark_type,
dialects_supported=[
Dialect.from_str("https://json-schema.org/draft/2020-12/schema"),
Dialect.from_str("https://json-schema.org/draft/2019-09/schema"),
Dialect.from_str("http://json-schema.org/draft-07/schema#"),
Dialect.from_str("http://json-schema.org/draft-06/schema#"),
Dialect.from_str("http://json-schema.org/draft-04/schema#"),
Dialect.from_str("http://json-schema.org/draft-03/schema#"),
],
description=description,
benchmarks=benchmarks,
varying_parameter=varying_parameter,
uri=URL.parse(Path(__file__).absolute().as_uri()),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
from url.url import URL

from bowtie._benchmarks import Benchmark, BenchmarkGroup
from bowtie._core import Dialect


def get_benchmark():

name = "contains"
benchmark_type = "keyword"
description = "A benchmark for validation of the `contains` keyword."
max_array_length = 100000
varying_parameter = "Array length"

max_array_size = 100000
array_size = 1000

array_length = 1000
benchmarks = []
while array_size <= max_array_size:
while array_length <= max_array_length:

start = [37] + [0] * (array_size - 1)
middle = [0] * (array_size // 2) + [37] + [0] * (array_size // 2)
end = [0] * (array_size - 1) + [37]
invalid = [0] * array_size
start = [37] + [0] * (array_length - 1)
middle = [0] * (array_length // 2) + [37] + [0] * (array_length // 2)
end = [0] * (array_length - 1) + [37]
invalid = [0] * array_length

tests = (
[
Expand All @@ -29,18 +30,18 @@ def get_benchmark():
dict(description="End of array", instance=end),
dict(description="Invalid array", instance=invalid),
]
if array_size == max_array_size
if array_length == max_array_length
else [
dict(description="Middle of array", instance=middle),
]
)

benchmarks.append(
Benchmark.from_dict(
name=f"Array Size - {array_size}",
name=f"Array length - {array_length}",
description=(
"Validating contains keyword over an array "
f"of size {array_size}"
f"of length {array_length}"
),
schema={
"type": "array",
Expand All @@ -49,11 +50,19 @@ def get_benchmark():
tests=tests,
),
)
array_size *= 10
array_length *= 10

return BenchmarkGroup(
name=name,
benchmark_type=benchmark_type,
description=description,
dialects_supported=[
Dialect.from_str("https://json-schema.org/draft/2020-12/schema"),
Dialect.from_str("https://json-schema.org/draft/2019-09/schema"),
Dialect.from_str("http://json-schema.org/draft-07/schema#"),
Dialect.from_str("http://json-schema.org/draft-06/schema#"),
],
benchmarks=benchmarks,
uri=URL.parse(Path(__file__).absolute().as_uri()),
varying_parameter=varying_parameter,
)
50 changes: 0 additions & 50 deletions bowtie/benchmarks/keywords/draft2020-12/maxItems.py

This file was deleted.

56 changes: 0 additions & 56 deletions bowtie/benchmarks/keywords/draft2020-12/maxLength.py

This file was deleted.

Loading