Answer the question
In order to leave comments, you need to log in
What is the most accurate way to measure the execution time of a function in Python?
How to accurately calculate the execution time of a function in Python?
Currently I'm using the following decorator:
def timing(f):
@wraps(f)
def wrapper(*args, **kwargs)-> str:
start = monotonic_ns()
result = f(*args, **kwargs)
ellapsed_time = monotonic_ns()-start
return result, ellapsed_time
return wrapper
Answer the question
In order to leave comments, you need to log in
def timing(f):
@wraps(f)
def wrapper(*args, **kwargs):
start_time = timeit.default_timer()
result = f(*args, **kwargs)
ellapsed_time = timeit.default_timer() - start_time
return result, ellapsed_time
return wrapper
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question