[Tutor] Re: Speeding up file processing?
Abel Daniel
abli at freemail.hu
Tue Nov 11 22:07:19 EST 2003
Clay Shirky writes:
> So I have a webserver log, and need to post process it a bit. I wrote a
> simple script in both python and perl, and the perl runs just about twice as
> fast.
>
> Here are the two scripts -- the logic is line-by-line identical, except for
> one try/except idiom. My question is: what should I do to speed up the
> python?
[...snipped code...]
I haven't tried it but maybe the following help:
- merge the two 'if re.search(): continue' into one search
- use pre-compiled regexes (i.e. use re.compile. In your python
version you to compile the same regexes for every line, and I think
that's what slows you down.)
--
Abel Daniel
ps. Please don't write to a mailling list by replying to an unrelated
mail. Your post will show up in the wrong place for mail-clients
which can handle threading.
More information about the Tutor
mailing list