Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python timer decorator

import time
import functools
def time_it(func):
  @functools.wraps(func)
  def wrapper(*args, **kwargs):
    start = time.perf_counter() # Start Time
    result = func(*args, **kwargs)
    end = time.perf_counter() # End Time
	print(f"function {func.__name__} ran in {end - start:0.4f} seconds")
  	return result
  return wrapper

@time_it
def some_function(sec: int):
  time.sleep(sec)

if __name__ == "__main__":
  some_function(5)
Comment

PREVIOUS NEXT
Code Example
Python :: making a basic network scanner using python 
Python :: change text in legend matplotlib 
Python :: self-xss meaning 
Python :: pandas divide one column by another 
Python :: numpy stack arrays vertically 
Python :: pygame how to find the full screen mode 
Python :: return count of substring in a string 
Python :: python create folder 
Python :: numpy array length 
Python :: python file hidden 
Python :: pandas for column in dataframe 
Python :: apply same shuffle to two arrays numpy 
Python :: how to fix Crypto.Cipher could not be resolved in python 
Python :: dataframe standardise 
Python :: print specific list item python 
Python :: drop rows from dataframe based on column value 
Python :: how to change python version 
Python :: render django 
Python :: convert text to speech in python 
Python :: flask tutorials 
Python :: flask port 
Python :: how to remove items from list in python 
Python :: combination 
Python :: web scraping python beautifulsoup 
Python :: pyspark dropna in one column 
Python :: beautiful soup 4 
Python :: how to change size of turtle in python 
Python :: loop throughthe key and the values of a dict in python 
Python :: python socket recv set timeout 
Python :: Image Watermarking in python 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =