Jun-17-2020, 12:26 PM
Hi all!
I recently tried to build a new IO class from python built-in IO classes. I noticed some performance degradation for these new classes. I wondering if anyone knows what might be the possible cause/fix for this.
I recently tried to build a new IO class from python built-in IO classes. I noticed some performance degradation for these new classes. I wondering if anyone knows what might be the possible cause/fix for this.
from _io import FileIO, BufferedReader
class FileIO_new(FileIO): ()
class BufferedReader_new(BufferedReader): ()
def built_in_io():
# a 3.5 MB file
raw = FileIO('filename', 'r')
buffer = BufferedReader(raw)
lines = buffer.readlines()
buffer.close()
def new_io():
raw = FileIO_new('filenmae','r')
buffer = BufferedReader_new(raw)
lines = buffer.readlines()
buffer.close()
>>>%timeit built_in_io()
1.79 ms ± 14.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
>>>%timeit new_io()
5.25 ms ± 87 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
