readline()

Tom Funk _spam_sux_tdfunk at _spam_sux_nettally.com
Thu Mar 23 13:39:05 EST 2000


In an article posted 22 Mar 2000 19:55:11 GMT,
Dana Booth (dana at mmi.oz.net) said:
> 
> Is readline() not very efficiant? 
> [snip]
> Anyway, I'm pretty new to Python, is there a better way to analyze
> textfiles? Or is the re.search slowing it down?
> 

Anytime you want to optimize an app for speed, regardless of programming 
language used, step one should always be to profile the code.  This will 
give you a definitive picture of where your code is slowest, and where to 
focus your efforts.

Luckily Python comes with a profiler (man, I love this language :-). 
Section 10, "The Python Profiler": 

   http://www.python.org/doc/current/lib/profile.html

discusses this module.

After you profile your code, and if the re or string modules turn out to 
be the bottleneck for your code, you might take a look at Marc-Andre 
Lemburg's mxTextTools module.  I've fiddled with it a little bit and for 
text pattern matching it goes like a bat out of hell. ;-)

See http://starship.skyport.net/~lemburg/mxTextTools.html.

However, before you start massively tweaking you code, do yourself a 
favor and profile it.  That one step could be very enlightening.

-- 
-=< tom >=-
Thomas D. Funk                           |       "Software is the lever
Software Engineering Consultant          | Archimedes was searching for"
Advanced Systems Design, Tallahassee FL. |




More information about the Python-list mailing list