• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import os
2import re
3import sys
4from subprocess import Popen
5
6_filename_re = re.compile(r"^bench_(.*?)\.py$")
7bench_directory = os.path.abspath(os.path.dirname(__file__))
8
9
10def list_benchmarks():
11    result = []
12    for name in os.listdir(bench_directory):
13        match = _filename_re.match(name)
14        if match is not None:
15            result.append(match.group(1))
16    result.sort(key=lambda x: (x.startswith("logging_"), x.lower()))
17    return result
18
19
20def run_bench(name):
21    print(name)
22    Popen(
23        [sys.executable, "-m", "timeit", "-s", f"from bench_{name} import run", "run()"]
24    ).wait()
25
26
27def main():
28    print("=" * 80)
29    print("Running benchmark for MarkupSafe")
30    print("-" * 80)
31    os.chdir(bench_directory)
32    for bench in list_benchmarks():
33        run_bench(bench)
34    print("-" * 80)
35
36
37if __name__ == "__main__":
38    main()
39