In the future I'll write multiple small scripts in Python 3 which I want to time. One way would be to write every script like this:
# functions definitions go here
if __name__ == '__main__':
import time
start = time.time()
# my code
end = time.time()
print("This script took {} seconds to execute".format(end - start))
But I would have to write this into every single of these scripts. What would be the best way to time my script without including this code every single time (without losing accuracy - I'm aware of time ./script.py
)?