This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Huge performance difference between read() and fread()


Rutger Hofman wrote:
Hi list,

I have a board with an PXA270 and 32MB of flash, part of which is configured as a jffs2 flash file system with Flash/v2 and legacy interface. I also have language/C and many other C components configured in, the relevant functions are open()/read() and fopen()/fread().

Now, if I read a file of size 503549 on this jffs2 file system, the performance is *wildly* different for read() and fread():

file "/fpga/guardian_v3_rev_b.svf" size 503549
read file /fpga/guardian_v3_rev_b.svf size 503549 takes 0.863116
fread file /fpga/guardian_v3_rev_b.svf size 503549 takes 16.601978

Times are in seconds.

Question: why are the timings a factor of 20 apart? Why are the timings different at all? I'd think that both do more or less exactly the same thing, although at a different interface.

This provides at least part of the answer:


the data above were obtained with a buffer size of 8K. It appears that FILEs have a buffer size of 256. If I change the buffer size in my test program to 256, I get the following timings:

file "/fpga/guardian_v3_rev_b.svf" size 503549
read file /fpga/guardian_v3_rev_b.svf size 503549 takes 15.767474
fread file /fpga/guardian_v3_rev_b.svf size 503549 takes 16.624629

OK, so the difference all but disappears. So if I want to have some performance in reading I'd better increase the FILE buffer size. I'll check for setvbuf and friends.

Rutger Hofman
VU Amsterdam


-- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]