Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site nbires.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxj!houxm!vax135!cornell!uw-beaver!tektronix!hplabs!hao!nbires!pdj From: pdj@nbires.UUCP (Paul Jensen) Newsgroups: net.unix Subject: Re: Speed of read vs. fread Message-ID: <365@nbires.UUCP> Date: Wed, 23-Jan-85 20:15:30 EST Article-I.D.: nbires.365 Posted: Wed Jan 23 20:15:30 1985 Date-Received: Sun, 27-Jan-85 05:44:15 EST References: <626@ihlts.UUCP> Organization: NBI,Inc, Boulder CO Lines: 19 > Which is faster, read/write or fread/fwrite? > ... > Bob Lied ihnp4!ihlts!lied We found that fread was MUCH slower than read on our Vax 780 when reading structures greater than about 256 - 512 bytes, and MUCH faster than read below that. It is about a factor of 3 slower than read for 8K chunks, and about 5 times slower than read for 16 byte chunks. fwrite behaves similarly. The problem is apparently due to the per character overhead of getc/putc. Fortunately, there is a simple fix. If you peek to see how much is currently in the buffer and use bcopy (or memcpy) to move in what you need, you can get fread's performance back up to what read can do for large chunks and still have the big 5:1 advantage over read for small chunks. Thus, you shouldn't have to choose. -- Paul Jensen NBI {hao,ucbvax,allegra}!nbires!pdj (303) 444-5710 x3054