[docs]deftimeit_old(logger:logging.Logger|None=None,level:int=logging.INFO,label:str|None=None,threshold_ms:float=10.0,# <── new parameter (default: 10 ms))->Callable[[F],F]:""" Decorator factory that measures wall-clock time of a function and reports it only if the elapsed time exceeds a threshold. Args: logger: Logger to use (default: None -> print). level: Logging level if logger is provided. label: Optional label to override function.__qualname__ in the message. threshold_ms: Minimum duration (in milliseconds) to report (default: 10.0). Usage: @timeit() # prints if >10 ms @timeit(threshold_ms=1.0) # prints if >1 ms @timeit(logging.getLogger()) # logs instead of printing @timeit(label="my_step") # custom label """def_decorator(func:F)->F:ifinspect.iscoroutinefunction(func):@functools.wraps(func)asyncdefwrapper(*args:Any,**kwargs:Any)->Any:name=labelorfunc.__qualname__start=time.perf_counter()try:returnawaitfunc(*args,**kwargs)finally:elapsed=(time.perf_counter()-start)*1000.0# msifelapsed>=threshold_ms:msg=f"{name} finished in {format_elapsed_time(elapsed)}"iflogger:logger.log(level,msg)else:print(msg)returncast(F,wrapper)@functools.wraps(func)defwrapper(*args:Any,**kwargs:Any)->Any:name=labelorfunc.__qualname__start=time.perf_counter()try:returnfunc(*args,**kwargs)finally:elapsed=(time.perf_counter()-start)*1000.0# msifelapsed>=threshold_ms:msg=f"{name} finished in {format_elapsed_time(elapsed)}"iflogger:logger.log(level,msg)else:print(msg)returncast(F,wrapper)return_decorator