Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site wanginst.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!wanginst!perlman From: perlman@wanginst.UUCP (Gary Perlman) Newsgroups: net.unix Subject: Re: Speed of read vs. fread Message-ID: <136@wanginst.UUCP> Date: Mon, 21-Jan-85 22:03:02 EST Article-I.D.: wanginst.136 Posted: Mon Jan 21 22:03:02 1985 Date-Received: Thu, 24-Jan-85 07:14:44 EST References: <626@ihlts.UUCP> Organization: Wang Institute, Tyngsboro, MA 01879 USA Lines: 35 > Which is faster, read/write or fread/fwrite? > > Bob Lied ihnp4!ihlts!lied There is no comparison. Here are some times for copying /etc/termcap (38123 chars). SIZE NAME COMMENT 6144 fgetputc using fgetc and fputc with stdio 7168 freadwrite using fread and fwrite BUFSIZ blocks with stdio 6144 getputc using getc and putc (macros) with stdio 5120 readwrite using read and write BUFSIZ blocks (no stdio) The results: PROGRAM user sys total fgetputc 2.1 0.2 2.3 freadwrite 1.1 0.1 1.2 getputc 0.7 0.1 0.8 readwrite 0.0 0.1 0.1 That is a huge effect! A factor of 23. Some observations: fgetc and fputc are functions which getc and putc are macros. The overhead of 38123 (times 2) function calls is immense. I think all the stdio functions are doing reads and writes. It looks like fread and fwrite are using more. I am not sure, but there may be some strange interactions if read and write are used directly in conjunction with stdio. I am posting the benchmarking programs to net.sources. Gary Perlman/Wang Institute/Tyngsboro, MA/01879/(617) 649-9731