Eric Wilson Eric Wilson - 4 years ago 161
Python Question

How do you determine a processing time in Python?

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();
long timeAfter = System.currentTimeMillis();
elapsed time = timeAfter - timeBefore;

I'm sure it's even easier in Python. Can anyone help?

Answer Source

Equivalent in python would be:

>>> import time
>>> tic = time.clock()
>>> toc = time.clock()
>>> toc - tic

It's not clear what are you trying to do that for? Are you trying to find the best performing method? Then you should prob have a look at timeit.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download