I am trying to get the execution time spent on a single line of code. Doing this for multiple lines and/or writing code every time like in the example below is just frustrating. Is there a better way to do this? See the example below.
import pandas as pd
import datetime
start_time = datetime.datetime.now()
df = pd.read_csv('dummy.csv')
print('Time spent reading: {}'.format(datetime.datetime.now() - start_time))
start_time = datetime.datetime.now()
df.head(n=100)
print('Time spent printing top 100: {}'.format(datetime.datetime.now() - start_time))