Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!thumper!ulysses!andante!mit-eddie!ll-xn!ames!amdahl!pyramid!voder!apple!dan
From: dan@apple.UUCP
Newsgroups: comp.sys.mac.programmer
Subject: Re: Optimal buffer size
Message-ID: <11508@apple.Apple.Com>
Date: 2 Jun 88 20:23:36 GMT
References: <7161@watdragon.waterloo.edu>
Reply-To: dan@apple.UUCP (Dan Allen)
Distribution: comp
Organization: Apple Computer Inc, Cupertino, CA
Lines: 32
Posted: Thu Jun  2 16:23:36 1988

There is no optimal buffer size that works in all cases and with all
hard disks.

Having said that, I have found (experimentally) that 8K works nicely
with hard disks in the 20 MB range, and I use 32K for some of my fast
text filters that I use on the 40-80MB drives.

That is, I use 32K buffers for stdin and stdout in my MPW Tools, for
example, and IO is dramatically improved.  (After doing an fopen, use
setvbuf)  However, more is NOT always better: 64K buffers are actually
slower!  It all depends on your disk, your application, how many open
files you have, you fragmented your disk is, etc..

Another tip: in MPW, a RAM cache setting (in the Control Panel) of
32-64K has been found to be optimal by Ira Ruben, the author of the MPW
Assembler.  He says 32-64K is the ONLY way to go.  He programs
exclusively using MPW Asm and MPW Pascal.

HOWEVER, using MPW C is a different ballgame.  MPW C does not have
(currently, but it will in 3.0) any load/dump mechanism.  Therefore MPW
C has to read and reread all of the equates files every compile.  This
makes for a lot of disk reading and greatly slows down things.  In that
case, you would like to have all of your header files in RAM, so setting
a RAM cache of about 256K (if you can afford it memory wise) really
helps MPW C.

BOTTOM LINE: experiment with your language and hard disk.  Write a
little tool and do some measuring.  Remember, measure, THEN optimize.

Dan Allen
Software Explorer
Apple Computer