[SciPy-user] tic toc in Matlab versus genutils.clock() in IPython

Fernando Perez fperez at colorado.edu
Thu Jun 5 13:34:36 EDT 2003


Pearu Peterson wrote:
> On Thu, 5 Jun 2003, Fernando Perez wrote:
> 
> 
>>I don't know how matlab works, so my comments are of limited value. 
>>genutils.clock() in ipython gives you:
>>
>>- under unix, the user+system time as returned by the getrusage system call. 
> 
> 
> IMHO, the returned user+system time is not very reliable, especially on
> multiuser system or when for some reason swapping is under progress or 
> .... In such cases I wouldn't use genutils.clock() for measuring the
> efficiency of the code as the timing results may be is influenced by
> unrelated system activities.
> 
> Recall that under linux scipy_test provides jiffies function that returns
> the user time, not the user+system time. With jiffies one should get
> the same results every time the same code is run, no matter if
> the system is idle (up to a current python process) or swapping as crazy.

I actually debated a lot whether to add system time or not to the returned 
value.  While it is true that there may be corner cases where your process 
gets charged for system time, I decided to leave it in for a specific reason: 
  if your code is consistently using a significant amount of system time, it 
may well have issues of  over-hungry memory usage.

I agree, however, that without having a way to distinguish user/system time, 
the current implementation of genutils.clock() is not enough to distinguish 
these issues.  Perhaps I'll change it to return _only_ user time in the next 
release, it's a trivial change.

However, when I'm timing my own numerical codes, what I use is the timer class 
here included. This is unix-only, but it allows me to take readings along the 
way conveniently, and I can distinguish between user and system time.

I include it here in case anyone wants to use it.  It is not meant to time 
short code snippets, but rather to instrument timing into a large code which 
runs for a long time, with a minimal amount of effort.

Comments/improvements are welcome.

Best,

f.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Timer.py
Type: text/x-python
Size: 4092 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20030605/9de147bf/attachment.py>


More information about the SciPy-User mailing list