Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python 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'
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #code #execution #time
ADD COMMENT
Topic
Name
1+2 =