36
36
from mypy .errors import Errors , CompileError , ErrorInfo , report_internal_error
37
37
from mypy .util import (
38
38
DecodeError , decode_python_encoding , is_sub_path , get_mypy_comments , module_prefix ,
39
- read_py_file , hash_digest , is_typeshed_file , is_stub_package_file , get_top_two_prefixes
39
+ read_py_file , hash_digest , is_typeshed_file , is_stub_package_file , get_top_two_prefixes ,
40
+ time_ref , time_spent_us
40
41
)
41
42
if TYPE_CHECKING :
42
43
from mypy .report import Reports # Avoid unconditional slow import
@@ -2039,7 +2040,7 @@ def parse_file(self) -> None:
2039
2040
else :
2040
2041
manager .log ("Using cached AST for %s (%s)" % (self .xpath , self .id ))
2041
2042
2042
- t0 = time . perf_counter ()
2043
+ t0 = time_ref ()
2043
2044
2044
2045
with self .wrap_context ():
2045
2046
source = self .source
@@ -2086,7 +2087,7 @@ def parse_file(self) -> None:
2086
2087
self .tree .ignored_lines ,
2087
2088
self .ignore_all or self .options .ignore_errors )
2088
2089
2089
- self .time_spent_us += int (( time . perf_counter () - t0 ) * 1e6 )
2090
+ self .time_spent_us += time_spent_us ( t0 )
2090
2091
2091
2092
if not cached :
2092
2093
# Make a copy of any errors produced during parse time so that
@@ -2123,7 +2124,7 @@ def semantic_analysis_pass1(self) -> None:
2123
2124
options = self .options
2124
2125
assert self .tree is not None
2125
2126
2126
- t0 = time . perf_counter ()
2127
+ t0 = time_ref ()
2127
2128
2128
2129
# Do the first pass of semantic analysis: analyze the reachability
2129
2130
# of blocks and import statements. We must do this before
@@ -2143,7 +2144,7 @@ def semantic_analysis_pass1(self) -> None:
2143
2144
if options .allow_redefinition :
2144
2145
# Perform more renaming across the AST to allow variable redefinitions
2145
2146
self .tree .accept (VariableRenameVisitor ())
2146
- self .time_spent_us += int (( time . perf_counter () - t0 ) * 1e6 )
2147
+ self .time_spent_us += time_spent_us ( t0 )
2147
2148
2148
2149
def add_dependency (self , dep : str ) -> None :
2149
2150
if dep not in self .dependencies_set :
@@ -2201,10 +2202,10 @@ def compute_dependencies(self) -> None:
2201
2202
def type_check_first_pass (self ) -> None :
2202
2203
if self .options .semantic_analysis_only :
2203
2204
return
2204
- t0 = time . perf_counter ()
2205
+ t0 = time_ref ()
2205
2206
with self .wrap_context ():
2206
2207
self .type_checker ().check_first_pass ()
2207
- self .time_spent_us += int (( time . perf_counter () - t0 ) * 1e6 )
2208
+ self .time_spent_us += time_spent_us ( t0 )
2208
2209
2209
2210
def type_checker (self ) -> TypeChecker :
2210
2211
if not self ._type_checker :
@@ -2222,17 +2223,17 @@ def type_map(self) -> Dict[Expression, Type]:
2222
2223
def type_check_second_pass (self ) -> bool :
2223
2224
if self .options .semantic_analysis_only :
2224
2225
return False
2225
- t0 = time . perf_counter ()
2226
+ t0 = time_ref ()
2226
2227
with self .wrap_context ():
2227
2228
return self .type_checker ().check_second_pass ()
2228
- self .time_spent_us += int (( time . perf_counter () - t0 ) * 1e6 )
2229
+ self .time_spent_us += time_spent_us ( t0 )
2229
2230
2230
2231
def finish_passes (self ) -> None :
2231
2232
assert self .tree is not None , "Internal error: method must be called on parsed file only"
2232
2233
manager = self .manager
2233
2234
if self .options .semantic_analysis_only :
2234
2235
return
2235
- t0 = time . perf_counter ()
2236
+ t0 = time_ref ()
2236
2237
with self .wrap_context ():
2237
2238
# Some tests (and tools) want to look at the set of all types.
2238
2239
options = manager .options
@@ -2255,7 +2256,7 @@ def finish_passes(self) -> None:
2255
2256
self .free_state ()
2256
2257
if not manager .options .fine_grained_incremental and not manager .options .preserve_asts :
2257
2258
free_tree (self .tree )
2258
- self .time_spent_us += int (( time . perf_counter () - t0 ) * 1e6 )
2259
+ self .time_spent_us += time_spent_us ( t0 )
2259
2260
2260
2261
def free_state (self ) -> None :
2261
2262
if self ._type_checker :
0 commit comments