Skip to content

Instantly share code, notes, and snippets.

@PrudhviVajja
Created November 11, 2020 01:23
Show Gist options
  • Save PrudhviVajja/31e51655139fe703e604d6450bc7c417 to your computer and use it in GitHub Desktop.
Save PrudhviVajja/31e51655139fe703e604d6450bc7c417 to your computer and use it in GitHub Desktop.
Timer Decorator
from functools import wraps
import time
def timeit(func):
@wraps(func)
def wrapper(*args, **kwargs):
print("Tracking function: " + func.__name__ + "()")
start = time.time()
func(*args, **kwargs)
end = time.time()
print("Time taken by the function to run is " + str(end-start))
return wrapper
@timeit
def looper(*args, **kwargs):
print(f"args = {args}")
print(f"kwargs = {kwargs}")
for loop in kwargs.values():
for i in range(loop):
return "Watch Looper If you haven't | rating=9/10"
looper(2, 3, 4, loop1=10, loop2=11, loop3=12, loop4=15)
# Ouput
🤩 ››› python3 timeitdecorator.py
Tracking function: lopper()
args = (2, 3, 4)
kwargs = {'loop1': 10, 'loop2': 11, 'loop3': 12, 'loop4': 15}
Time taken by the function to run is 1.811981201171875e-05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment