Skip to content

Commit 7a2da6b

Browse files
committed
Pull in another microbenchmark that can be improved later.
1 parent b1f6973 commit 7a2da6b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
A benchmark which tries to compare the possible slow subparts of validation.
3+
"""
4+
from referencing import Registry
5+
from referencing.jsonschema import DRAFT202012
6+
from rpds import HashTrieMap, HashTrieSet
7+
8+
from jsonschema import Draft202012Validator
9+
10+
schema = {
11+
"type": "array",
12+
"minLength": 1,
13+
"maxLength": 1,
14+
"items": {"type": "integer"}
15+
}
16+
17+
hmap = HashTrieMap()
18+
hset = HashTrieSet()
19+
20+
registry = Registry()
21+
22+
v = Draft202012Validator(schema)
23+
24+
25+
def registry_data_structures():
26+
return hmap.insert("foo", "bar"), hset.insert("foo")
27+
28+
29+
def registry_add():
30+
resource = DRAFT202012.create_resource(schema)
31+
return registry.with_resource(uri="urn:example", resource=resource)
32+
33+
34+
if __name__ == "__main__":
35+
from pyperf import Runner
36+
runner = Runner()
37+
38+
runner.bench_func("HashMap/HashSet insertion", registry_data_structures)
39+
runner.bench_func("Registry insertion", registry_add)
40+
runner.bench_func("Success", lambda: v.is_valid([1]))
41+
runner.bench_func("Failure", lambda: v.is_valid(["foo"]))
42+
runner.bench_func("Metaschema validation", lambda: v.check_schema(schema))

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ multi_line_output = 3
136136
[tool.mypy]
137137
ignore_missing_imports = true
138138
show_error_codes = true
139+
exclude = ["jsonschema/benchmarks/*"]
139140

140141
[tool.ruff]
141142
line-length = 79

0 commit comments

Comments
 (0)