How to make regexes faster? (Python v. OmniMark)
Fernando Pérez
fperez528 at yahoo.com
Fri Apr 19 16:03:30 EDT 2002
Donn Cave wrote:
> Part of the problem is that when you write something like a "grep"
> in Python and in Perl, the Perl program will naturally be written
> like while ($line = <STDIN>) {...}, and the Python program will
> naturally be written like while 1: line = sys.stdin.readline() ...
>
I don't know how far back (version wise) this works, but I'd rather use:
for line in sys.stdin.xreadlines():
which should be pretty good. And I guess if the name lookups aren't optimized
away (which I don't know) you can always do
xread = sys.stdin.xreadlines
for line in xread():
I'm not saying that perl can't be faster than python at some things. Simply
that I wouldn't be surprised if the factor of 10 loss was more due to someone
writing python code using perlisms than to python's limitations. It's
probably similar to the kind of problems you'd get in perl if you tried to
coerce it into doing things the python ways.
Each tool has its own optimal way of being used, and such way must be learned
before claims such as the aboved carry any weight at all.
Cheers,
f.
More information about the Python-list
mailing list