extract elements of n char from a list

Fernando Perez fperez528 at yahoo.com
Fri Jul 26 18:19:46 EDT 2002


<posted & mailed>

Alex Martelli wrote:

> Tim Peters' introduction
> to the Algorithms chapter of "Python Cookbook" (the printed edition
> that O'Reilly just launched) is invaluable in showing you exactly
> how to perform such little benchmarks for accuracy and solidity.

Well, partly in honor to the quality of your posts here I went ahead and 
purchased the Cookbook. It will make for nice reading, I look forward to 
enjoying it.

However, I'd like to mention a _minor_ inaccuracy in the text you refer to by 
Tim. He says that on Unix machines, time.clock() returns the user time from 
your process. Technically that's not 100% true, as it returns the sum of 
(user+system) time consumed by your process. 

The clock.c sources confirm this (from glibc-2.2.5):

/* Return the time used by the program so far (user time + system time).  */
clock_t
clock ()
{
  struct tms buf;

  if (__times (&buf) < 0)
    return (clock_t) -1;

  return buf.tms_utime + buf.tms_stime;
}


I know it's a minor point, but it may be worth noting if you are trying to do 
careful timings.

The benchmark package I noted in my previous post implements 4 separate 
clocks to deal with this, allowing you to time 

- user
- system
- user+system - like time.clock()
- user&system separately, returned in a tuple.

It provides an interface for doing timings with repeated calls and averaging, 
and any one of the 4 above mentioned clocks.

Just a minor point.

Cheers,

f.



More information about the Python-list mailing list