File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed 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
136
136
[tool .mypy ]
137
137
ignore_missing_imports = true
138
138
show_error_codes = true
139
+ exclude = [" jsonschema/benchmarks/*" ]
139
140
140
141
[tool .ruff ]
141
142
line-length = 79
You can’t perform that action at this time.
0 commit comments