Debian Codegraph @

benchmarks/new_benchmark.py

raw symbols SCIP
1 import json
2 import subprocess
3 import re
4 import statistics
5 from glob import glob
6 from collections import defaultdict
7 import sys
8
9 cmds = {
10 # "baseline": ["python3"],
11 # "scalene": ["python3", "-m", "scalene", "--json", "--outfile", "/dev/null"],
12 # "scalene-cpu": ["python3", "-m", "scalene", "--json", "--cpu", "--outfile", "/dev/null"],
13 # "scalene-cpu-gpu": ["python3", "-m", "scalene", "--json", "--cpu", "--gpu", "--outfile", "/dev/null"],
14 # "scalene-5M": ["python3", "-m", "scalene", "--json", "--outfile", "/dev/null", "--allocation-sampling-window", "5242883"],
15 # "scalene-10M": ["python3", "-m", "scalene", "--json", "--outfile", "/dev/null", "--allocation-sampling-window", "10485767"],
16 # "scalene-20M": ["python3", "-m", "scalene", "--json", "--outfile", "/dev/null", "--allocation-sampling-window","20971529"],
17 # "memray": [
18 # "python3",
19 # "-m",
20 # "memray",
21 # "run",
22 # "--trace-python-allocators",
23 # "-f",
24 # "-o",
25 # "/tmp/memray.out",
26 # ],
27 # "fil": ["fil-profile", "-o", "/tmp/abc", '--no-browser', "run"],
28 # "austin_full": ["austin", "-o", "/dev/null", "-f"],
29 # "austin_cpu": ["austin", "-o", "/dev/null"],
30 # 'py-spy': ['py-spy', 'record', '-o', '/tmp/profile.svg', '--', 'python3'],
31 # 'cProfile': ['python3', '-m', 'cProfile', '-o', '/dev/null'],
32 "yappi_wall": ["python3", "-m", "yappi", "-o", "/dev/null", "-c", "wall"],
33 "yappi_cpu": ["python3", "-m", "yappi", "-o", "/dev/null", "-c", "cpu"],
34 # 'pprofile_det': ['pprofile', '-o', '/dev/null'],
35 # 'pprofile_stat': ['pprofile', '-o', '/dev/null', '-s', '0.001'],
36 # 'line_profiler': ['kernprof', '-l', '-o', '/dev/null', '-v'],
37 # 'profile': ['python3', '-m', 'profile', '-o', '/dev/null']
38 }
39 result_regexp = re.compile(r"Time elapsed:\s+([0-9]*\.[0-9]+)")
40
41
42 def main():
43 out = defaultdict(lambda: {})
44
45 for progname in [
46 # "./test/expensive_benchmarks/bm_mdp.py",
47 # "./test/expensive_benchmarks/bm_async_tree_io.py none",
48 # "./test/expensive_benchmarks/bm_async_tree_io.py io",
49 # "./test/expensive_benchmarks/bm_async_tree_io.py cpu_io_mixed",
50 # "./test/expensive_benchmarks/bm_async_tree_io.py memoization",
51 # "./test/expensive_benchmarks/bm_fannukh.py",
52 # "./test/expensive_benchmarks/bm_pprint.py",
53 # "./test/expensive_benchmarks/bm_raytrace.py",
54 # "./test/expensive_benchmarks/bm_sympy.py",
55 "./test/expensive_benchmarks/bm_docutils.py"
56 ]:
57 for profile_name, profile_cmd in cmds.items():
58 times = []
59 for i in range(5):
60 print(
61 f"Running {profile_name} on {progname} using \"{' '.join(profile_cmd + progname.split(' '))}\"...",
62 end="",
63 flush=True,
64 )
65 result = subprocess.run(
66 profile_cmd + progname.split(" "),
67 stderr=subprocess.STDOUT,
68 stdout=subprocess.PIPE,
69 )
70
71 output = result.stdout.decode("utf-8")
72 # print(output)
73 match = result_regexp.search(output)
74 if match is not None:
75 print(
76 f"... {match.group(1)}",
77 end=("\n" if profile_name != "memray" else ""),
78 )
79 times.append(round(100 * float(match.group(1))) / 100.0)
80 if profile_name == "memray":
81 res2 = subprocess.run(
82 [
83 "time",
84 sys.executable,
85 "-m",
86 "memray",
87 "flamegraph",
88 "-f",
89 "/tmp/memray.out",
90 ],
91 capture_output=True,
92 env={"TIME": "Time elapsed: %e"},
93 )
94 output2 = res2.stderr.decode("utf-8")
95 match2 = result_regexp.search(output2)
96 if match2 is not None:
97 print(f"... {match2.group(1)}")
98 times[-1] += round(100 * float(match2.group(1))) / 100.0
99 else:
100 print("... RUN FAILED")
101 # exit(1)
102 else:
103 print("RUN FAILED")
104 # exit(1)
105 out[profile_name][progname] = times
106 with open("yappi.json", "w+") as f:
107 json.dump(dict(out), f)
108
109
110 if __name__ == "__main__":
111 main()