How to read lines from a mmapped file?

前端 未结 4 1559
孤独总比滥情好
孤独总比滥情好 2020-12-24 02:48

Is seems that the mmap interface only supports readline(). If I try to iterate over the object I get character instead of complete lines.

What would be the \"python

4条回答
  •  一向
    一向 (楼主)
    2020-12-24 03:20

    Python 2.7 32bit on Windows is more than twice as fast on an mmapped file:

    On a 27MB, 509k line text file (my 'parse' function is not interesting it mostly just readline()'s very rapidly):

    with open(someFile,"r") as f:
        if usemmap:
            m=mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
        else:
            m=f
            e.parse(m)
    

    With MMAP:

    read in 0.308000087738
    

    Without MMAP:

    read in 0.680999994278
    

提交回复
热议问题