@@ -304,13 +304,11 @@ def _check_results(results: dict[str, FrameworkMetrics]) -> list[str]:
304304 f"base-cli cold invocation p95 exceeded { COLD_INVOCATION_P95_BUDGETS_MS [BENCHMARK_PLATFORM ]:.0f} ms"
305305 )
306306
307- for framework in FRAMEWORKS :
308- warm_p95 = _metric_p95 (results .get (framework , {}), "warm_invocation_ms" )
309- if warm_p95 is not None and warm_p95 > WARM_INVOCATION_P95_BUDGETS_MS [BENCHMARK_PLATFORM ]:
310- failures .append (
311- f"{ framework } warm no-op invocation p95 exceeded "
312- f"{ WARM_INVOCATION_P95_BUDGETS_MS [BENCHMARK_PLATFORM ]:.0f} ms"
313- )
307+ warm_p95 = _metric_p95 (base , "warm_invocation_ms" )
308+ if warm_p95 is not None and warm_p95 > WARM_INVOCATION_P95_BUDGETS_MS [BENCHMARK_PLATFORM ]:
309+ failures .append (
310+ f"base-cli warm no-op invocation p95 exceeded { WARM_INVOCATION_P95_BUDGETS_MS [BENCHMARK_PLATFORM ]:.0f} ms"
311+ )
314312
315313 lifecycle_p95 = _metric_p95 (base , "lifecycle_warm_invocation_ms" )
316314 click_p95 = _metric_p95 (results .get ("click" , {}), "warm_invocation_ms" )
@@ -443,10 +441,7 @@ def _format_number(value: object) -> str:
443441
444442
445443def _measure_import (iterations : int , framework : str ) -> list [float ]:
446- package_root = Path (__file__ ).resolve ().parents [1 ] / "lib" / "python"
447- environment = dict (os .environ )
448- existing_path = environment .get ("PYTHONPATH" )
449- environment ["PYTHONPATH" ] = f"{ package_root } { os .pathsep } { existing_path } " if existing_path else str (package_root )
444+ environment = _subprocess_environment ()
450445 samples : list [float ] = []
451446 for _ in range (iterations ):
452447 started = time .perf_counter_ns ()
@@ -462,10 +457,7 @@ def _measure_import(iterations: int, framework: str) -> list[float]:
462457
463458
464459def _measure_cold_invocations (iterations : int , framework : str ) -> list [float ]:
465- package_root = Path (__file__ ).resolve ().parents [1 ] / "lib" / "python"
466- environment = dict (os .environ )
467- existing_path = environment .get ("PYTHONPATH" )
468- environment ["PYTHONPATH" ] = f"{ package_root } { os .pathsep } { existing_path } " if existing_path else str (package_root )
460+ environment = _subprocess_environment ()
469461 programs = {
470462 "base-cli" : (
471463 "import base_cli\n "
@@ -558,9 +550,20 @@ def main(ctx: Any) -> None:
558550
559551 command = cast (Any , app .click_command )
560552 runner = CliRunner ()
553+ # Keep this probe in the same ambient Click runner environment as the
554+ # comparator. The isolated HOME used by production scenarios measures a
555+ # different contract and would make the lifecycle delta incomparable.
561556 return _measure_runner (iterations , lambda : runner .invoke (command , []).exit_code )
562557
563558
559+ def _subprocess_environment () -> dict [str , str ]:
560+ package_root = Path (__file__ ).resolve ().parents [1 ] / "lib" / "python"
561+ environment = dict (os .environ )
562+ existing_path = environment .get ("PYTHONPATH" )
563+ environment ["PYTHONPATH" ] = f"{ package_root } { os .pathsep } { existing_path } " if existing_path else str (package_root )
564+ return environment
565+
566+
564567def _measure_click_invocations (iterations : int ) -> list [float ]:
565568 import click
566569 from click .testing import CliRunner
0 commit comments