Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

time decorator python

from functools import wraps
from time import time
def measure(func):
    @wraps(func)
    def _time_it(*args, **kwargs):
        start = int(round(time() * 1000))
        try:
            return func(*args, **kwargs)
        finally:
            end_ = int(round(time() * 1000)) - start
            print(f"Total execution time: {end_ if end_ > 0 else 0} ms")
    return _time_it
@measure
def hello():
    print('hello world')

hello()
Comment

PREVIOUS NEXT
Code Example
Python :: install easygui 
Python :: ctypes run as administrator 
Python :: ticks font size matplotlib 
Python :: install re package python 
Python :: tk table python 
Python :: pascal triangle python 
Python :: python check if a variable is an pandaDataframe 
Python :: python get user home directory 
Python :: how to print image with cv2 
Python :: pandas print first column 
Python :: python convert number to base 
Python :: pandas drop row by condition 
Python :: conda python 3.8 
Python :: python time using timeit module 
Python :: sklearn random forest regressor 
Python :: install a specific version of django 
Python :: renomear colunas pandas 
Python :: delete element of a list from another list python 
Python :: pandas astype string 
Python :: how to append to text file with new line by line in python 
Python :: beautifulsoup find by class 
Python :: pytorch tensor change dimension order 
Python :: ImportError: cannot import name ‘json’ from itsdangerous 
Python :: python datetime add minutes 
Python :: python - remove scientific notation 
Python :: np array to df 
Python :: using bs4 to obtain html element by id 
Python :: DtypeWarning: Columns (47) have mixed types.Specify dtype option on import or set low_memory=False 
Python :: python install module from script 
Python :: column string to datetime python 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =