Speed of read vs. fread
malcolm at ee.UUCP
malcolm at ee.UUCP
Tue Jan 22 10:59:00 AEST 1985
/* Written 9:36 pm Jan 19, 1985 by lied at ihlts in ee:net.unix */
Which is faster, read/write or fread/fwrite?
Depends on what you are doing. If you are doing single character IO then
by all means use fread/fwrite. The time it takes to put the character in
the buffer is insignificant to the expense of a syscall.
On the other hand large chunks of IO (several BUFSIZ's at a time) are much
more efficient with read/write. One of my research programs saved many
seconds of CPU time by using write() to output large matrices (100k bytes)
for debugging.
The question is where to draw the line. I would recomend that in general
to use fread/fwrite. If you are reading/writing more than 5 or 10k at a
time (one call to read/write) then you'll start saving a little time by
using read/write.
Charter member of the Purdue
team to stamp out unnecessary
sys-calls.
Malcolm
pur-ee!malcolm
malcolm at purdue.arpa
More information about the Comp.unix
mailing list