Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site utah-gr.UUCP Path: utzoo!decvax!genrad!teddy!panda!talcott!harvard!seismo!utah-cs!utah-gr!thomas From: thomas@utah-gr.UUCP (Spencer W. Thomas) Newsgroups: net.unix Subject: Re: Speed of read vs. fread Message-ID: <1314@utah-gr.UUCP> Date: Wed, 23-Jan-85 02:06:37 EST Article-I.D.: utah-gr.1314 Posted: Wed Jan 23 02:06:37 1985 Date-Received: Sat, 26-Jan-85 10:30:44 EST References: <626@ihlts.UUCP> Reply-To: thomas@utah-gr.UUCP (Spencer W. Thomas) Organization: Univ of Utah CS Dept Lines: 51 Summary: In article <626@ihlts.UUCP> lied@ihlts.UUCP (Bob Lied) writes: >I've been told that fread/fwrite is faster because >it buffers. On the other hand, I've been told that >read/write is faster because (a) read always does >a one block read-ahead if it can and (b) it avoids >the overhead of the fread/fwrite abstraction. > >Given a choice, and doing I/O in chunks instead of >characters, which should I use for performance? >Please explain your selection, and no lectures on >tuning too early, OK? > Well, I did a simple experiment, contrasting read and write vs fread and fwrite performance on a 4.2a (or is it 4.3) system. This has the fread and fwrite enhancements (the idea for which was taken from System V, I believe, so results should be comparable). My experiment, with results tabulated below, shows that fread and fwrite are MUCH better for small record sizes, and are worse for large record sizes (but not too much). These tests were run on a basically unloaded VAX 750 running the enhanced 4.2bsd system (which may be called 4.3 someday, I dunno). The file system block size for the first test was 8192/1024 and for the second it was 4096/512. (For those of you not familiar with the 4.2 file system, the first number is the file system block size, and the 2nd is the fragment size. For files this size, you can mostly ignore the fragment size.) Reading /vmunix (274432 bytes) with record | read fread size |user system clock % |user system clock % --------+-------------------------------+------------------------------- 1 |17.4 499.7 9:35 89% |40.0 1.5 1:10 68% 512 |0.0 1.4 0:02 74% |0.2 0.4 0:01 47% 8192 |0.0 0.4 0:01 41% |0.2 0.5 0:01 54% Writing a 1Mb file with record | write fwrite size |user system clock % |user system clock % --------+-------------------------------+------------------------------- 28 |3.3 134.5 2:34 89% |5.6 3.6 0:10 88% 1024 |0.1 6.5 0:07 88% |0.7 3.6 0:05 77% 8192 |0.0 3.4 0:04 77% |0.8 3.3 0:04 89% P.S., this also shows the performance of the 4.2 filesystem -- note that I can read a 270Kb file in about 1 second, and can write a 1Mb file in about 4 seconds. Not too shabby! -- =Spencer ({ihnp4,decvax}!utah-cs!thomas, thomas@utah-cs.ARPA) <<< Silly quote of the week >>>