Speed up reading in a compressed bz2 file ('rb' mode)
问题 I have a BZ2 file of more than 10GB. I'd like to read it without decompressing it into a temporary file (it would be more than 50GB). With this method: import bz2, time t0 = time.time() time.sleep(0.001) # to avoid / by 0 with bz2.open("F:\test.bz2", 'rb') as f: for i, l in enumerate(f): if i % 100000 == 0: print('%i lines/sec' % (i/(time.time() - t0))) I can only read ~ 250k lines per second. On a similar file, first decompressed , I get ~ 3M lines per second, i.e. a x10 factor: with open("F