CRT fread vs Windows ReadFile

Hello,
we are testing performance of a file system filter, and the test tool uses
both crt fread and ReadFile from Windows. We have huge files (in GBs) and we
do a sequential 1 byte read to traverse the file (in one of the test cases).

We find that the ReadFile API is way faster than the fread implementation.

Am I missing something here? or is this expected?

thanks

AP

.shell -ci "uf ${$arg1} " grep -i call | sed s/.*call// | sed s/(.*//

lkd> $$>a< scripts\recurcalltree.txt msvcrt!fread
msvcrt!_SEH_prolog
msvcrt!_lock_file
msvcrt!_fread_lk
msvcrt!fread+0x42
msvcrt!_SEH_epilog
.shell: Process exited
lkd> $$>a< scripts\recurcalltree.txt msvcrt!_fread_lk
msvcrt!_read
msvcrt!_filbuf
.shell: Process exited
lkd> $$>a< scripts\recurcalltree.txt msvcrt!_read
msvcrt!_SEH_prolog
msvcrt!_lock_fhandle
msvcrt!_read_lk
msvcrt!_errno
msvcrt!__doserrno
msvcrt!_read+0x87
msvcrt!_errno
msvcrt!__doserrno
msvcrt!_SEH_epilog
.shell: Process exited
lkd> $$>a< scripts\recurcalltree.txt msvcrt!_read_lk
dword ptr [msvcrt!_imp__ReadFile
dword ptr [msvcrt!_imp__GetLastError
msvcrt!_errno
msvcrt!__doserrno
msvcrt!_dosmaperr
dword ptr [msvcrt!_imp__ReadFile
dword ptr [msvcrt!_imp__GetLastError
msvcrt!_lseeki64_lk
.shell: Process exited

fread ends up in ReadFile Import

On 8/20/11, A P wrote:
> Hello,
> we are testing performance of a file system filter, and the test tool uses
> both crt fread and ReadFile from Windows. We have huge files (in GBs) and we
> do a sequential 1 byte read to traverse the file (in one of the test cases).
>
> We find that the ReadFile API is way faster than the fread implementation.
>
> Am I missing something here? or is this expected?
>
> thanks
>
> AP
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


thanks and regards

raj_r

>We find that the ReadFile API is way faster than the fread implementation.

What are the caching flags passed to CreateFile in both cases?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

fread() does buffering and calls _filbuf(), which is a wrapper around read(), which is a wrapper around ReadFile.

fread() for 1 byte is just *dst++ = *src++ and should be much faster then ReadFile, but fopen() can call CreateFile with caching flags other then the ones used in ReadFile test.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntfsd…
IIRC fread has an extra buffering of the data (for case you want to
read per character) and calls ReadFile internally. Check out CRT
sources.

----- P?VODN? ZPR?VA -----
Od: “A P”
Komu: “Windows File Systems Devs Interest List”

P?edm?t: [ntfsd] CRT fread vs Windows ReadFile
Datum: 19.8.2011 - 21:44:59

> Hello,
> we are testing performance of a file system
> filter, and the test tool uses
> both crt fread and ReadFile from Windows. We have
> huge files (in GBs) and we
> do a sequential 1 byte read to traverse the file
> (in one of the test cases).
>
> We find that the ReadFile API is way faster than
> the fread implementation.
>
> Am I missing something here? or is this expected?
>
> thanks
>
> AP
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system
> seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of
> OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>