[Python-Dev] RE: [Patches] [Patch #102915] xreadlines : readlines :: xrange : range
Tim Peters
tim.one@home.com
Mon, 1 Jan 2001 14:20:53 -0500
[gvanrossum, in an SF patch comment]
> Bah. I don't like this one bit. More complexity for a little
> bit of extra speed.
> I'm keeping this open but expect to be closing it soon unless I
> hear a really good argument why more speed is really needed in
> this area. Down with code bloat and creeping featurism!
Without judging "the solution" here, "the problem" is that everyone's first
attempt to use line-at-a-time file input in Perl:
while (<F>} {
... $_ ...;
}
runs 2-5x faster then everyone's first attempt in Python:
while 1:
line = f.readline()
if not line:
break
... line ...
It would be beneficial to address that *somehow*, cuz 2-5x isn't just "a
little bit"; and by the time you walk a newbie thru
while 1:
lines = f.readlines(hintsize)
if not lines:
break
for line in lines:
... line ...
they feel like maybe Perl isn't so obscure after all <wink>.
Does someone have an elegant way to address this? I believe Jeff's shot at
elegance was the other part of the patch, using (his new) xreadlines under
the covers to speed the fileinput module.
reading-text-files-is-very-common-ly y'rs - tim