Why gfortran`s stream access is so slow?

Jerry DeLisle jvdelisle@verizon.net
Sat Nov 3 05:37:00 GMT 2007


shark 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.
> For testing, i wrote programs below:
> ----------------------------------------------C
> Version---------------------------------------------
> #include <stdio.h>
> #include <stdlib.h>
> int main(int argc, char * argv[])
> {
>   if(argc!=3)
>     {
>       printf("no enought parameters!\n");
>       return -1;
>     }
>   FILE *srcFile,*destFile;
>   unsigned char byte;
>   int i,len;
>   srcFile=fopen(argv[1],"rb+");
>   destFile=fopen(argv[2],"wb+");
>   fseek(srcFile,0,SEEK_END);
>   len=ftell(srcFile);
>   printf("len=%d",len);
>   rewind(srcFile);
>   for(i=len;i>0;i--)
>     {
>       byte=fgetc(srcFile);
>       fputc(byte,destFile);
>     }
>   fclose(destFile);
>   fclose(srcFile);
>   return 0;
> }
> ------------------------------------------------GFortran--------------------------------------------
> 
> 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
I have a patch testing now for this.

Results before patch:
real    0m9.360s
user    0m1.434s
sys     0m7.918s

Results after patch:
real    0m5.018s
user    0m0.882s
sys     0m4.136s

Its a a significant improvement.  It does not compare with C because of some of 
the overheads we have to deal with, but we will keep working on those.

Jerry



More information about the Fortran mailing list