-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
Description
PyPy uses a JIT, so the initial run of a function may be misleading: after some number of runs the JIT kicks in, and then it will run much faster. CPython is working on a JIT too, so this may be relevant to future CPython releases as well (possibly even 3.13).
The code would likely look like:
import platform # NEW
IS_JIT = platform.python_implementation().lower() == "pypy" # NEW
def _run_with_instrumentation(
lib: LibType,
nodeId: str,
config: pytest.Config,
fn: Callable[..., Any],
*args,
**kwargs,
):
is_gc_enabled = gc.isenabled()
if is_gc_enabled:
gc.collect()
gc.disable()
result = None
def __codspeed_root_frame__():
nonlocal result
result = fn(*args, **kwargs)
if SUPPORTS_PERF_TRAMPOLINE:
# Warmup CPython performance map cache
__codspeed_root_frame__()
if IS_JIT: # NEW
# Warm up JIT
for _ in range(100): # NEW
__codspeed_root_frame__() # NEW
lib.zero_stats()
lib.start_instrumentation()
__codspeed_root_frame__()
lib.stop_instrumentation()
uri = get_git_relative_uri(nodeId, config.rootpath)
lib.dump_stats_at(uri.encode("ascii"))
if is_gc_enabled:
gc.enable()
return resultedgarrmondragon