471,312 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,312 software developers and data experts.

mmap disk performance

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?

Cheers!
Nov 20 '07 #1
1 2558
On Nov 20, 2007 10:31 AM, koara <ko***@atlas.czwrote:
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.
Nov 20 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by netbogus | last post: by
7 posts views Thread by Michael | last post: by
26 posts views Thread by myeates | last post: by
13 posts views Thread by George Sakkis | last post: by
2 posts views Thread by beejisbrigit | last post: by
1 post views Thread by James T. Dennis | last post: by
9 posts views Thread by Owen Zhang | last post: by
6 posts views Thread by osnot | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.