From: Chasecreek Systemhouse <[EMAIL PROTECTED]>
> On Sun, 31 Oct 2004 22:04:33 +0100, Jenda Krynicky <[EMAIL PROTECTED]>
> wrote:
> 
> > Something like that. 1024 is one K. So 8*1024 is 8KB.
> > 
> > I don't know what the size of a block is when reading from the
> > particular disk storing that file, but the block size is usualy some
> > power of 2 in KB. 2KB, 4KB, 8KB, 16KB, 32KB. It would of course be
> > most efficient if I was reading the file in chunks equal to the
> > block size, but 8KB seems to me like a reasonable guess.
> 
> 
> PMFJI  =)
> 
> I would like to think that high-level programmers simply read and
> write $strings, @arrays, etc, and allow the under-lying OpSys (XP,
> Solaris, FC3, etc) to worry about the file access methods.
> 
> Operating systems can access data at whatever speed the filesystem
> format (Ext2, Ext3, Reiser, Quorums, Raids, Fly-swatter) would allow
> without people generally having to worry about sectors, blocks, etc.

That's why I would not sweat about this too much. But if I can make 
the computer's work easier just by choosing a good constant I will.

It seems though that the constant doesn't matter much. I've tried to 
copy a 709MB file using a tiny script that looked like this:

        open IN, '<', 'Kour.avi';
        open OUT, '>', 'Kour.avi.out';
        binmode(IN);binmode(OUT);

        my $time = time();
        my $buff;
        while(read IN, $buff, 32*1024) {
                print OUT $buff;
        }

        print "Done in " . (time() - $time) . " seconds\n";

and it took 171s with 8*1024 and 176 with 5000 and 32*1024 byte 
chunks.

OTOH converting it to sysopen/sysread/syswrite made a big difference. 
THe time went down to 79s with 32*1024 byte chunks but 180-185s with 
5000 byte ones.

        use Fcntl;
        sysopen IN, 'Kour.avi', O_RDONLY;
        sysopen OUT, 'Kour.avi.out', O_WRONLY | O_CREAT;

        my $time = time();
        my $buff;
        while(sysread IN, $buff, 32*1024) {
                syswrite(OUT, $buff);
        }

        print "Done in " . (time() - $time) . " seconds\n";

Of course under normal circumstances you have much better things to 
worry about than what chunksize to use ;-)

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to