Perl vs. Python for text manipulation

Ganesan R rganesan at myrealbox.com
Sat Jan 24 11:11:33 CET 2004


> Is that all that people mean, though, when they talk about Perl's
> superiority for text mangling?  Is there more to it?  --

It's probably not just regular expressions. In my case, Python's IO
performance is simply not upto the mark. Even Python 2.3 is atleast twice
slower than perl for text manipulation simply because of this IO
overhead. As mentioned in an earlier post, I had to fix a program that
searched for patterns in a gzipped word list to launch zgrep in a pipe and
post process it in python to get acceptable performance.

The perl "built-in" idioms for text processing is not only a syntactic
convenience, there are real performance advantages. For example a simple
perl loop like

while (<>) { }

is nearly 6 times slower in python (8 time slower with Python 2.2) using
fileinput. Every appears to know that fileinput is slower and avoid it when
performance is a concern; but even manually doing the equivalent is slower
in python. I've simply switched back to using perl for my text processing
needs - especially one off or short scripts where I don't care so much about
maintainability as about finishing the job faster.

Ganesan

--
Ganesan R




More information about the Python-list mailing list