@@ -55,9 +55,17 @@ def clone(target_dir: str, commit: str | None) -> None:
55
55
subprocess .run (["git" , "checkout" , commit ], check = True , cwd = target_dir )
56
56
57
57
58
- def run_benchmark (compiled_dir : str , check_dir : str ) -> float :
58
+ def edit_python_file (fnam : str ) -> None :
59
+ with open (fnam ) as f :
60
+ data = f .read ()
61
+ data += "\n #"
62
+ with open (fnam , "w" ) as f :
63
+ f .write (data )
64
+
65
+
66
+ def run_benchmark (compiled_dir : str , check_dir : str , * , incremental : bool ) -> float :
59
67
cache_dir = os .path .join (compiled_dir , ".mypy_cache" )
60
- if os .path .isdir (cache_dir ):
68
+ if os .path .isdir (cache_dir ) and not incremental :
61
69
shutil .rmtree (cache_dir )
62
70
env = os .environ .copy ()
63
71
env ["PYTHONPATH" ] = os .path .abspath (compiled_dir )
@@ -72,6 +80,10 @@ def run_benchmark(compiled_dir: str, check_dir: str) -> float:
72
80
]
73
81
cmd += glob .glob (os .path .join (abschk , "mypy/*.py" ))
74
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" ))
75
87
t0 = time .time ()
76
88
# Ignore errors, since some commits being measured may generate additional errors.
77
89
subprocess .run (cmd , cwd = compiled_dir , env = env )
@@ -80,6 +92,12 @@ def run_benchmark(compiled_dir: str, check_dir: str) -> float:
80
92
81
93
def main () -> None :
82
94
parser = argparse .ArgumentParser ()
95
+ parser .add_argument (
96
+ "--incremental" ,
97
+ default = False ,
98
+ action = "store_true" ,
99
+ help = "measure incremental run (fully cached)" ,
100
+ )
83
101
parser .add_argument (
84
102
"-n" ,
85
103
metavar = "NUM" ,
@@ -89,6 +107,7 @@ def main() -> None:
89
107
)
90
108
parser .add_argument ("commit" , nargs = "+" , help = "git revision to measure (e.g. branch name)" )
91
109
args = parser .parse_args ()
110
+ incremental : bool = args .incremental
92
111
commits = args .commit
93
112
num_runs : int = args .n + 1
94
113
@@ -127,7 +146,7 @@ def main() -> None:
127
146
items = list (enumerate (commits ))
128
147
random .shuffle (items )
129
148
for i , commit in items :
130
- tt = run_benchmark (target_dirs [i ], self_check_dir )
149
+ tt = run_benchmark (target_dirs [i ], self_check_dir , incremental = incremental )
131
150
# Don't record the first warm-up run
132
151
if n > 0 :
133
152
print (f"{ commit } : t={ tt :.3f} s" )
0 commit comments