Search
 
SCRIPT & CODE EXAMPLE
 

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'
Comment

PREVIOUS NEXT
Code Example
Python :: python get image dimensions 
Python :: how to read from a file into a list in python 
Python :: beautifulsoup find by class 
Python :: get files in directory python 
Python :: grid in pygame 
Python :: add sheet to existing workbook openpyxl 
Python :: find all text in site python 
Python :: python get current number of threads 
Python :: read os.system output python 
Python :: python remove first and last character from string 
Python :: bmi python 
Python :: opencv write text 
Python :: install aws sdk ubuntu 20.04 command line 
Python :: python copy dir 
Python :: save list python 
Python :: list to csv pandas 
Python :: django form password field 
Python :: disable devtools listening on ws://127.0.0.1 python 
Python :: pandas plot xlabel 
Python :: python check operating system 
Python :: python sort list by last element 
Python :: python selenium get style 
Python :: python os.getenv not working 
Python :: python check if hotkey pressed 
Python :: plt.clear 
Python :: random from list python 
Python :: python get webpage source 
Python :: how to count stopwords in df 
Python :: len table python 
Python :: load saved model pyspark 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =