Python slow for filter scripts

Terry Reedy tjreedy at udel.edu
Tue Oct 28 16:10:02 EST 2003


"Peter Mutsaers" <plm at gmx.li> wrote in message
news:9769adc8.0310281233.5fc5d252 at posting.google.com...
> However, I tried the most simple while(<>) {print;} in Perl versus
> Python, just a copy from stdin to stdout, to see how fast the basic
> filter can be.
>
> I found that on my (linux) PC, the Python version was 4 times
slower.

There are several ways to copy a file in Python.  Some are much faster
than others.  I believe 'for line in file: print line' might be
fastest with python code.  There is also shutil.copyfile(src,dst) or
one of other variants.  Which did you use?

> Is that normal, does it disqualify Python for simple filter scripts?

I have read that Perl is optimized for file read/write in a way that
Python is not, so this may not be most representative comparison for
your actual app.  In any case, relevance of relative speed depends on
absolute speed (think about milleseconds versus hours).

Terry J. Reedy






More information about the Python-list mailing list