python get time executed by function 1

python get time executed by function

from datetime import datetime
start_time = datetime.now()
# do your work here
end_time = datetime.now()
print('Duration: {}'.format(end_time - start_time))

Here is what the above code is Doing:
1. We import the datetime module.
2. We create a variable called start_time and set it to datetime.now().
3. We do our work.
4. We create a variable called end_time and set it to datetime.now().
5. We print the difference between end_time and start_time.

Similar Posts