@@ -63,27 +63,27 @@ def edit_python_file(fnam: str) -> None:
63
63
f .write (data )
64
64
65
65
66
- def run_benchmark (compiled_dir : str , check_dir : str , * , incremental : bool ) -> float :
66
+ def run_benchmark (
67
+ compiled_dir : str , check_dir : str , * , incremental : bool , code : str | None
68
+ ) -> float :
67
69
cache_dir = os .path .join (compiled_dir , ".mypy_cache" )
68
70
if os .path .isdir (cache_dir ) and not incremental :
69
71
shutil .rmtree (cache_dir )
70
72
env = os .environ .copy ()
71
73
env ["PYTHONPATH" ] = os .path .abspath (compiled_dir )
72
74
env ["PYTHONHASHSEED" ] = "1"
73
75
abschk = os .path .abspath (check_dir )
74
- cmd = [
75
- sys .executable ,
76
- "-m" ,
77
- "mypy" ,
78
- "--config-file" ,
79
- os .path .join (abschk , "mypy_self_check.ini" ),
80
- ]
81
- cmd += glob .glob (os .path .join (abschk , "mypy/*.py" ))
82
- cmd += glob .glob (os .path .join (abschk , "mypy/*/*.py" ))
83
- if incremental :
84
- # Update a few files to force non-trivial incremental run
85
- edit_python_file (os .path .join (abschk , "mypy/__main__.py" ))
86
- edit_python_file (os .path .join (abschk , "mypy/test/testcheck.py" ))
76
+ cmd = [sys .executable , "-m" , "mypy" ]
77
+ if code :
78
+ cmd += ["-c" , code ]
79
+ else :
80
+ cmd += ["--config-file" , os .path .join (abschk , "mypy_self_check.ini" )]
81
+ cmd += glob .glob (os .path .join (abschk , "mypy/*.py" ))
82
+ cmd += glob .glob (os .path .join (abschk , "mypy/*/*.py" ))
83
+ if incremental :
84
+ # Update a few files to force non-trivial incremental run
85
+ edit_python_file (os .path .join (abschk , "mypy/__main__.py" ))
86
+ edit_python_file (os .path .join (abschk , "mypy/test/testcheck.py" ))
87
87
t0 = time .time ()
88
88
# Ignore errors, since some commits being measured may generate additional errors.
89
89
subprocess .run (cmd , cwd = compiled_dir , env = env )
@@ -112,12 +112,20 @@ def main() -> None:
112
112
type = int ,
113
113
help = "set maximum number of parallel builds (default=8)" ,
114
114
)
115
+ parser .add_argument (
116
+ "-c" ,
117
+ metavar = "CODE" ,
118
+ default = None ,
119
+ type = str ,
120
+ help = "measure time to type check Python code fragment instead of mypy self-check" ,
121
+ )
115
122
parser .add_argument ("commit" , nargs = "+" , help = "git revision to measure (e.g. branch name)" )
116
123
args = parser .parse_args ()
117
124
incremental : bool = args .incremental
118
125
commits = args .commit
119
126
num_runs : int = args .num_runs + 1
120
127
max_workers : int = args .j
128
+ code : str | None = args .c
121
129
122
130
if not (os .path .isdir (".git" ) and os .path .isdir ("mypyc" )):
123
131
sys .exit ("error: Run this the mypy repo root" )
@@ -152,7 +160,7 @@ def main() -> None:
152
160
items = list (enumerate (commits ))
153
161
random .shuffle (items )
154
162
for i , commit in items :
155
- tt = run_benchmark (target_dirs [i ], self_check_dir , incremental = incremental )
163
+ tt = run_benchmark (target_dirs [i ], self_check_dir , incremental = incremental , code = code )
156
164
# Don't record the first warm-up run
157
165
if n > 0 :
158
166
print (f"{ commit } : t={ tt :.3f} s" )
0 commit comments