Re: measuring a function time



Someone should port Perl's Benchmark.pm module to python that's such a useful module to measure a functions execution time and CPU usage.

Sent from my iPhone 4.

On Jul 29, 2010, at 3:43 PM, "Benjamin J. Racine" <bjracine@xxxxxxxxxxx> wrote:

I just use ipython's functions (that are themselves just calls to the time module functions) for timing my functions...

Enter:
%timeit?
or
%time

At the Ipython command prompt to get started.

Ben R.

On Jul 29, 2010, at 7:43 AM, D'Arcy J.M. Cain wrote:

On Thu, 29 Jul 2010 08:45:23 -0400
Joe Riopel <goon12@xxxxxxxxx> wrote:
On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan <nt_mahmood@xxxxxxxxx> 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@xxxxxxxxx> | 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.
--
http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list
.



Relevant Pages

  • Re: measuring a function time
    ... At the Ipython command prompt to get started. ... The clock() method returns ... print time() - t, clock ...
    (comp.lang.python)
  • Re: measuring a function time
    ... Joe Riopel wrote: ... The clock() method returns ... processor time, not wall time. ... print time() - t, clock ...
    (comp.lang.python)