How to speed up reading bytes from file?
Grant Edwards
grante at visi.com
Fri Dec 6 13:01:59 EST 2002
In article <asqjrl$tis$00$1 at news.t-online.com>, Stephan Diehl wrote:
>> My "unpack" algorithm consists of reading a "byte", then optionally 1 to 15
>> "chars", then some number of bytes of words (2-byte network order)
>
> I haven't read your posting in great detail, so please excuse me, if I'm
> too far of the mark...
>
> Whatever you do, you should NEVER read single bytes from disk. The
> reason is quite simple: the disk can only access chunks of data anyway
> and not single bytes. So, for every byte you are reading, the disk (or
> diskdriver) will read a chunk and extract the byte you extracted.
> Just read in a whole block of data and work on that local in memory copy.
On any real OS, the disk buffering in the filesystem code will
do that for you when you read single bytes. You can, however,
avoid the user/kernel context switches by using mmap().
--
Grant Edwards grante Yow! WHO sees a BEACH
at BUNNY sobbing on a SHAG
visi.com RUG?!
More information about the Python-list
mailing list