I'm new to Python, and confused by the date/time documentation. I want to compute the time that it takes to perform a computation.
In java, I would write:
long timeBefore = System.currentTimeMillis(); doStuff(); long timeAfter = System.currentTimeMillis(); elapsed time = timeAfter - timeBefore;
I'm sure it's even easier in Python. Can anyone help?
Equivalent in python would be:
>>> import time >>> tic = time.clock() >>> toc = time.clock() >>> toc - tic
If you are trying to find the best performing method then you should probably have a look at timeit
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With