Here is a basic setup:
import time
start_time = time.time()
# code
print("time - {}".format(time.time()-start_time))
You can also make use of Python's function wrappers, and make a wrapper to time your functions. eg.
import time
def getime(func):
def func_wrapper(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
print("function {} completed in - {} seconds".format(
func.__name__,
time.time()-start_time))
return func_wrapper
# ------------ test example of wrapper --------- #
@getime
def foo():
for i in range(1000):
for j in range(2000):
pass
foo()
Output:
function foo completed in - 0.13300752639770508 seconds