Skip to content

Commit 1f3616b

Browse files
committed
Add benchmark for import time
1 parent a236135 commit 1f3616b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
A benchmark which measures the import time of jsonschema
3+
"""
4+
5+
import subprocess
6+
import sys
7+
8+
9+
def import_time(loops):
10+
total_us = 0
11+
for _ in range(loops):
12+
p = subprocess.run( # noqa: S603 (arguments are static)
13+
[sys.executable, "-X", "importtime", "-c", "import jsonschema"],
14+
stderr=subprocess.PIPE,
15+
stdout=subprocess.DEVNULL,
16+
check=True,
17+
)
18+
19+
line = p.stderr.splitlines()[-1]
20+
field = line.split(b"|")[-2].strip()
21+
us = int(field) # microseconds
22+
total_us += us
23+
24+
# pyperf expects seconds
25+
return total_us / 1_000_000.0
26+
27+
if __name__ == "__main__":
28+
from pyperf import Runner
29+
runner = Runner()
30+
31+
runner.bench_time_func("Import time (cumulative)", import_time)

0 commit comments

Comments
 (0)