[Python-Dev] Re: [Patches] [Patch #103082] speed up readline() using getc_unlocked()

Guido van Rossum guido@python.org
Wed, 03 Jan 2001 15:25:53 -0500


> >Summary: speed up readline() using getc_unlocked()
> 
> So what does the performance of this version look like?

Very slightly faster than the GNU getline() version.  Without GNU
getline, the old code was about 3.5 times slower.

Here are the current times on a 6 Mb file (fileinput.py has my
sourceforge speedup patch too):

$ ./python ~/rltest.py ~/termcapx10 
total 6252720 chars and 146250 lines; average line length 42.8
count_chars_lines     0.943  0.930
readlines_sizehint    0.544  0.540
using_fileinput       2.089  2.090
while_readline        0.956  0.960

For comparison, here's what Python 1.5.2 does with the same test
(which should be pretty close to what the released Python 2.0 does; I
don't have a copy of that handy).

$ python1.5 ~/rltest.py ~/termcapx10 
total 6252720 chars and 146250 lines; average line length 42.8
count_chars_lines     0.836  0.820
readlines_sizehint    0.523  0.520
using_fileinput       5.739  5.740
while_readline        3.670  3.670

I don't know why count_chars_lines got proportionally more slower than
readlines_sizehint.  (The += operator didn't make a difference either
way.)

--Guido van Rossum (home page: http://www.python.org/~guido/)