File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ))
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ multi_line_output = 3
136136[tool .mypy ]
137137ignore_missing_imports = true
138138show_error_codes = true
139+ exclude = [" jsonschema/benchmarks/*" ]
139140
140141[tool .ruff ]
141142line-length = 79
You can’t perform that action at this time.
0 commit comments