measuring a function time

D'Arcy J.M. Cain darcy at druid.net
Thu Jul 29 10:43:39 EDT 2010


On Thu, 29 Jul 2010 08:45:23 -0400
Joe Riopel <goon12 at gmail.com> wrote:
> On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan <nt_mahmood at yahoo.com> wrote:
> > the output should be 7600 (s) for example. What is the best and easiest way
> > to do that?
> 
> Take a look at time.clock()

I don't know if that's what he wants.  The clock() method returns
processor time, not wall time.

Python 2.6.5 (r265:79063, Jul  8 2010, 16:01:18) 
[GCC 4.1.3 20080704 prerelease (NetBSD nb2 20081120)] on netbsd5
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import time, clock, sleep
>>> t = time()
>>> print time() - t, clock()
0.000596046447754 0.03
>>> sleep(3)
>>> print time() - t, clock()
3.03474903107 0.03
>>> x = open("BIGFILE").read()
>>> print time() - t, clock()
10.2008538246 1.42

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list