Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 650
Eric Wilson Avatar asked Sep 23 '09 10:09

Eric Wilson


1 Answers

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.

like image 72
SilentGhost Avatar answered Oct 05 '22 14:10

SilentGhost