codekingpro/portable-devtools
114k
1"""2A benchmark which measures the import time of jsonschema3"""4 5import subprocess6import sys7 8 9def import_time(loops):10 total_us = 011 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) # microseconds22 total_us += us23 24 # pyperf expects seconds25 return total_us / 1_000_000.026 27if __name__ == "__main__":28 from pyperf import Runner29 runner = Runner()30 31 runner.bench_time_func("Import time (cumulative)", import_time)32 