Calculate execution time in Python

In any Python script you can easily count execution time. In Jupiter notebooks simply use built-in magic commands like


in the very beginning of the cell. Now with the IDEs like PyCharm you should use something like this:

import datetime as dt
t1 =
# your code here
t2 =
ft = t2 - t1
print("--- %s seconds ---" % ft.seconds)

You can actually also get seconds, days and even microseconds:

print("--- %s seconds ---" % ft.seconds)
print("--- %s ms ---" % ft.microseconds)
print("--- %s days ---" % ft.days)