By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

mmap disk performance

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.