[Tutor] get cpu time used by a python script

Kim Branson kim.branson at gmail.com
Wed Feb 7 06:05:00 CET 2007


Hi Chris,

that seems to be exactly what i need.

Cheers

Kim



 >>> import resource
 >>> def cpu_time():
... return resource.getrusage(resource.RUSAGE_SELF)[0]
...

Now try this out

 >>> def f():
... for i in xrange(100000):
... pass
...
 >>> start = cpu_time(); f(); dt = cpu_time() - start; print dt
0.008001
 >>> start = cpu_time(); f(); dt = cpu_time() - start; print dt
0.012001

On Feb 6, 2007, at 8:58 PM, Christopher Lucas wrote:

> python/python/545797?page=las



More information about the Tutor mailing list