Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python calculate code execution time

# python code execution time -- using wrapper
import time
def exec_time(func):
    def wrapper():
        start_time = time.time()
        result = func()
        elapsed = time.time() - start_time
        return elapsed, result
    return wrapper

@exec_time
def hlw():
    time.sleep(2)
    return "hello"

t, o = hlw()
print(t, o)  # 2.001209020614624 'hello'
 
PREVIOUS NEXT
Tagged: #python #calculate #code #execution #time
ADD COMMENT
Topic
Name
5+6 =