Re: Why gfortran`s stream access is so slow?
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Tue, 30 Oct 2007 23:12:50 -0800
CPLUSPLUS09@xxxxxxxxx wrote:
Hi, everyone, i want to why gfortran`s stream read write is so slow?default, so it should be ok while reading bytes and bytes.From gfortran`s manual, i know that gfortran`s I/O are buffered on
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
.
- References:
- Why gfortran`s stream access is so slow?
- From: CPLUSPLUS09@xxxxxxxxx
- Why gfortran`s stream access is so slow?
- Prev by Date: Memory/Stack corruption problems in c++/fortran application
- Next by Date: Re: Stack corruption and memory leak problems in c++/Fortran application
- Previous by thread: Why gfortran`s stream access is so slow?
- Next by thread: Stack corruption and memory leak problems in c++/Fortran application
- Index(es):