every time i run this code i get time 0.0, but i want exact time took by the function to run, i tried by increasing the values of arguments. pls help mi !!
import time
from functools import wraps
def calculate_time(function):
@wraps(function)
def wrapper(*args, **kwargs):
print(f"you are calling {function.__name__} function")
print(f"{function.__doc__}")
t1 = time.time()
returned_func = function(*args, **kwargs)
t2 = time.time()
total_time = t2 -t1
print(f"this function took {total_time} seconds")
return returned_func
return wrapper
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 101, 11, 12, 12, 1000000]
@calculate_time
def squares(n):
'''this function returns the squares of numbers'''
return [i**2 for i in range(1, n+1)]
squares(1000)