Daniel Hillier <daniel.hill...@gmail.com> added the comment:

Here's the script I used for profiling and the results I observed with and 
without the closed check in read:

import zipfile

test_zip = "time_test.zip"
test_name = "test_name.txt"

with zipfile.ZipFile(test_zip, "w") as zf:
    zf.writestr(test_name, "Hi there! " * 300)

with zipfile.ZipFile(test_zip) as zf:
    for i in range(100000):
        zf.read(test_name)

# Current code (no closed check), three different profiling sessions:
# ncalls  tottime  percall  cumtime  percall filename:lineno(function)
# 100000    0.612    0.000    6.638    0.000 zipfile.py:884(read)
# 100000    0.598    0.000    6.489    0.000 zipfile.py:884(read)
# 100000    0.600    0.000    6.485    0.000 zipfile.py:884(read)

# With closed check, three different profiling sessions:
# ncalls  tottime  percall  cumtime  percall filename:lineno(function)
# 100000    0.632    0.000    6.587    0.000 zipfile.py:884(read)
# 100000    0.623    0.000    6.564    0.000 zipfile.py:884(read)
# 100000    0.638    0.000    6.700    0.000 zipfile.py:884(read)

-------

I based this change on the what BytesIO does: 
https://github.com/python/cpython/blob/master/Lib/_pyio.py#L912

Let me know if you want me to make any changes.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37523>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to