forked from python-jsonschema/jsonschema
-
Notifications
You must be signed in to change notification settings - Fork 1
/
perftest
executable file
·46 lines (35 loc) · 1.02 KB
/
perftest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env python
"""
A *very* basic performance test.
"""
from __future__ import print_function
import argparse
import textwrap
import timeit
IMPORT = "from jsonschema import Draft3Validator, Draft4Validator, validate\n"
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--number", type=int, default=100)
arguments = parser.parse_args()
print("Validating {0} times.".format(arguments.number))
for name, benchmark in (
(
"Simple", """
validator = Draft3Validator(
{"type" : "object", "properties" : {"foo" : {"required" : True}}}
)
instance = {"foo" : 12, "bar" : 13}
"""
),
(
"Meta schema", """
validator = Draft3Validator(Draft3Validator.META_SCHEMA)
instance = validator.META_SCHEMA
"""
),
):
results = timeit.timeit(
number=arguments.number,
setup=IMPORT + textwrap.dedent(benchmark),
stmt="validator.validate(instance)",
)
print("{0:15}: {1} seconds".format(name, results))