Large gap between fwrite and write, and fread and read

Garrett Cooper youshi10 at u.washington.edu
Mon Jul 16 12:07:00 UTC 2007


Hello again Hackers,
    I ran some tests and I noticed a large difference in the cumulative 
sums of fwrite(2) vs write(3) and fread(2) vs read(3) (3-fold 
differences on a real machine).
    Please download 
<http://students.washington.edu/youshi10/posted/fat.tgz>, take a look at 
README for some results, and read for more details on how you can run 
the tests as well if curious, and feel free to send me the results if 
desired. If you do run the tests, please don't use the /tmp disk at all 
on the machine as it will most likely skew parts of the test, and please 
pay heed to the warning, otherwise the test box may become unusable.
    One thing that has me puzzled though... why is there such a large 
difference? Is it because fread(2) allows object by object instantiation 
(i.e. preallocates objects according to sizeof and returns the number of 
allocated figures), whereas read(3) just reads in raw lengths and 
returns the amount of chars scanned in? Does the same logic apply for 
fwrite(2) and write(3)?
Thanks,
-Garrett -- I really need to go to bed earlier.. haha.


More information about the freebsd-hackers mailing list