mmap disk performance

Chris Mellon arkanes at gmail.com
Tue Nov 20 12:02:54 EST 2007


On Nov 20, 2007 10:31 AM, koara <koara at atlas.cz> wrote:
> Hello all,
>
> i am using the mmap module (python2.4) to access contents of a file.
>
> My question regards the relative performance of mmap.seek() vs
> mmap.tell(). I have a generator that returns stuff from the file,
> piece by piece. Since other things may happen to the mmap object in
> between consecutive next() calls (such as another iterator's next()),
> i have to store the file position before yield and restore it
> afterwards by means of tell() and seek(). Is this correct?
>
> When restoring, is there a penalty for mmap.seek(pos) where the file
> position is already at pos (i.e., nothing happened to the file
> position in between, a common scenario)? If there is, is it worth
> doing
>
> if mmap.tell() != pos:
>     mmap.seek(pos)
>
> or such?
>

Measure it and see. I suspect that the cost of the check in Python
will outweigh any extra work the C code might do, but you should never
guess - just measure it.

This is also pretty unlikely to be any sort of hotspot in your
application - again, measure and see. Unless your profiler says you
spend a lot of time in mmap.seek calls, don't worry about it.



More information about the Python-list mailing list