Python vs. Java gzip performance

Serge Orlov Serge.Orlov at gmail.com
Sat Mar 18 00:16:59 EST 2006


Bill wrote:
> Is there something that can be improved in the Python version?

Seems like GzipFile.readlines is not optimized, file.readline works
better:

C:\py>python -c "file('tmp.txt', 'w').writelines('%d This is a test\n'
% n for n in range(10000))"

C:\py>python -m timeit "open('tmp.txt').readlines()"
100 loops, best of 3: 2.72 msec per loop

C:\py>python -m timeit "open('tmp.txt').readlines(1000000)"
100 loops, best of 3: 2.74 msec per loop

C:\py>python -m timeit "open('tmp.txt').read().splitlines(True)"
100 loops, best of 3: 2.79 msec per loop

Workaround has been posted already.

  -- Serge.




More information about the Python-list mailing list