Is it possible to speed-up python IO?

后端 未结 8 967

Consider this python program:

import sys

lc = 0
for line in open(sys.argv[1]):
    lc = lc + 1

print lc, sys.argv[1]

Running it on my 6GB

8条回答
  •  既然无缘
    2020-12-16 16:28

    plain "no".

    You've pretty much reached maximum disk speed.

    I mean, you could mmap the file, or read it in binary chunks, and use .count('\n') or something. But that is unlikely to give major improvements.

提交回复
热议问题