from datetime import datetime start = datetime.now() # some kind of code print(datetime.now() - start)