Efficient python programming...

Kragen Sitaker kragen at pobox.com
Sun Jun 9 03:50:33 CEST 2002


"James Kew" <james.kew at btinternet.com> writes:

> "gabor" <gabor at realtime.sk> wrote in message
> news:mailman.1023401650.18434.python-list at python.org...
> > for file in directory:
> >     file.printsize()
> 
> Finally, "printsize" as a method name suggests to me that the loop is more
> likely to be IO-bound than CPU-bound, so attempts to optimise the loop
> overhead may buy very little benefit.

Possible, but not likely --- how much I/O do you think it takes to
read an inode and put a line in an output buffer?

> 
> If it were me, I'd go with the first option for clarity; leave it unless and
> until a performance problem emerges and profiling points at this loop;
> consider algorithmic changes first (possibly merge the multiple IO
> operations into a single larger one?); and only then start sacrificing
> clarity for speed.
> 
> James




More information about the Python-list mailing list