Skip to content

Commit 20a631e

Browse files
committed
test(ts): measure CPU time in the normalizer scaling test to de-flake it
perf_counter counts wall-clock, which includes time the process is preempted off-CPU during a busy full-suite run, inflating the larger measurement and flaking the ratio. process_time counts only CPU work, isolating the algorithmic scaling. Follow-up to Graphify-Labs#3402.
1 parent 3b9356b commit 20a631e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎tests/test_ts_import_type_arguments.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,13 @@ def test_ts_normalizer_scales_linearly_on_large_files():
295295
each match by scanning every range made extraction quadratic, so `extract`
296296
spun at 100% CPU in the regex/scan path and never finished.
297297
298-
Assert on scaling, not wall-clock, so the test is not machine-dependent:
299-
doubling the input must not roughly quadruple the time.
298+
Assert on scaling, not absolute wall-clock, so the test is not
299+
machine-dependent: doubling the input must not roughly quadruple the time.
300+
Measure CPU time (``process_time``), not wall-clock (``perf_counter``): under
301+
a busy full-suite run the process is preempted, and wall-clock would count
302+
time slices spent scheduled off-CPU — inflating the larger measurement and
303+
flaking the ratio. CPU time counts only work actually done, so it isolates
304+
the algorithmic scaling regardless of load.
300305
"""
301306
import time
302307

@@ -309,13 +314,13 @@ def build(n: int) -> bytes:
309314

310315
def timed(n: int) -> float:
311316
source = build(n)
312-
start = time.perf_counter()
317+
start = time.process_time()
313318
_normalize_ts_import_types(source)
314-
return time.perf_counter() - start
319+
return time.process_time() - start
315320

316321
timed(200) # warm the grammar/parser import off the measured path
317-
small = min(timed(1000) for _ in range(3))
318-
large = min(timed(2000) for _ in range(3))
322+
small = min(timed(1000) for _ in range(5))
323+
large = min(timed(2000) for _ in range(5))
319324

320325
# Linear work doubles (~2x). Quadratic work quadruples (~4x). A generous
321326
# 3x ceiling separates the two without being flaky under load.

0 commit comments

Comments
 (0)