Re: Why gfortran`s stream access is so slow?



CPLUSPLUS09@xxxxxxxxx wrote:
Hi, everyone, i want to why gfortran`s stream read write is so slow?
From gfortran`s manual, i know that gfortran`s I/O are buffered on
default, so it should be ok while reading bytes and bytes.

The simple answers are that:

1) Unformatted stream is new, and hasn't been optimized much yet.
2) When it is, it will be optimized for larger than single byte access.

If you want a fair comparison you should probably use fread() and
fwrite() instead of getc() and putc(). There is at least a subroutine
call overhead for the usual implementation of Fortran READ and WRITE,
while getc() and putc() are usually C macros. I don't expect that to
make all the difference, but maybe some.

(snip of C program)

program fortCP
character(len=256) :: srcFile,destFile
character :: byte

if(command_argument_count().ne.2)then
print*,'agrument not enough!'
stop
end if
call get_command_argument(1,srcFile)
call get_command_argument(2,destFile)

open(10,file=trim(srcFile),form='unformatted',access='stream',status='old')

open(20,file=trim(destFile),form='unformatted',access='stream',status='replace')
do
read(10,end=500),byte
write(20),byte
end do
500 close(20)
close(10)
end program fortCP


Here`s the result.
32M File
GCC
real 0m2.925s
user 0m2.750s
sys 0m0.170s

GFORTRAN-4.2.2
real 9m48.880s
user 1m47.540s
sys 7m53.780s

The high system time looks almost like it is doing unbuffered I/O
(or flush() on each byte). The user time might be the overhead of
READ and WRITE calls.

-- glen

.