codekingpro/portable-devtools
114k
1"""2A benchmark for validation of schemas containing lots of useless keywords.3 4Checks we filter them out once, ahead of time.5"""6 7from pyperf import Runner8 9from jsonschema import Draft202012Validator10 11NUM_USELESS = 10000012schema = dict(13 [14 ("not", {"const": 42}),15 *((str(i), i) for i in range(NUM_USELESS)),16 ("type", "integer"),17 *((str(i), i) for i in range(NUM_USELESS, NUM_USELESS)),18 ("minimum", 37),19 ],20)21validator = Draft202012Validator(schema)22 23valid = 373724invalid = 1225 26 27if __name__ == "__main__":28 runner = Runner()29 runner.bench_func("beginning of schema", lambda: validator.is_valid(42))30 runner.bench_func("middle of schema", lambda: validator.is_valid("foo"))31 runner.bench_func("end of schema", lambda: validator.is_valid(12))32 runner.bench_func("valid", lambda: validator.is_valid(3737))33 