Speed of read vs. fread

Gary Perlman perlman at wanginst.UUCP
Tue Jan 22 13:03:02 AEST 1985


> 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



More information about the Comp.unix mailing list