diff --git a/IPython/genutils.py b/IPython/genutils.py index e4df2ef..467505c 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -5,7 +5,7 @@ General purpose utilities. This is a grab-bag of stuff I find useful in most programs I write. Some of these things are also convenient when working at the command line. -$Id: genutils.py 1930 2006-11-26 17:22:13Z vivainio $""" +$Id: genutils.py 2108 2007-02-23 00:31:17Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -163,16 +163,34 @@ StringTypes = types.StringTypes # If possible (Unix), use the resource module instead of time.clock() try: import resource - def clock(): - """clock() -> floating point number + def clocku(): + """clocku() -> floating point number - Return the CPU time in seconds (user time only, system time is - ignored) since the start of the process. This is done via a call to - resource.getrusage, so it avoids the wraparound problems in - time.clock().""" + Return the *USER* CPU time in seconds since the start of the process. + This is done via a call to resource.getrusage, so it avoids the + wraparound problems in time.clock().""" return resource.getrusage(resource.RUSAGE_SELF)[0] + def clocks(): + """clocks() -> floating point number + + Return the *SYSTEM* CPU time in seconds since the start of the process. + This is done via a call to resource.getrusage, so it avoids the + wraparound problems in time.clock().""" + + return resource.getrusage(resource.RUSAGE_SELF)[1] + + def clock(): + """clock() -> floating point number + + Return the *TOTAL USER+SYSTEM* CPU time in seconds since the start of + the process. This is done via a call to resource.getrusage, so it + avoids the wraparound problems in time.clock().""" + + u,s = resource.getrusage(resource.RUSAGE_SELF)[:2] + return u+s + def clock2(): """clock2() -> (t_user,t_system) @@ -180,7 +198,9 @@ try: return resource.getrusage(resource.RUSAGE_SELF)[:2] except ImportError: - clock = time.clock + # There is no distinction of user/system time under windows, so we just use + # time.clock() for everything... + clocku = clocks = clock = time.clock def clock2(): """Under windows, system CPU time can't be measured. diff --git a/doc/ChangeLog b/doc/ChangeLog index cb934f5..343429a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,14 @@ +2007-02-22 Fernando Perez + + * IPython/genutils.py (clock): I modified clock() to return total + time, user+system. This is a more commonly needed metric. I also + introduced the new clocku/clocks to get only user/system time if + one wants those instead. + + ***WARNING: API CHANGE*** clock() used to return only user time, + so if you want exactly the same results as before, use clocku + instead. + 2007-02-22 Ville Vainio * IPython/Extensions/ipy_p4.py: Extension for improved