This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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: [Patch, fortran] PR35339 Optimize implied do loops in io statements


Hi Nicolas,

gcc@dcm-linux:~/pr/35339> gfortran -O3 perf_test.f90
gcc@dcm-linux:~/pr/35339> time ./a.out

real    0m1.879s
user    0m1.838s
sys     0m0.040s
gcc@dcm-linux:~/pr/35339> gfortran-7 -O3 perf_test.f90
gcc@dcm-linux:~/pr/35339> time ./a.out

real    0m1.929s
user    0m1.901s
sys     0m0.028s

For formatted I/O, the advantage will not be large because
of the CPU time needed for converting numbers to decimal.
People who care about speed in I/O use unformatted I/O,
and there is a big advantage to using an array slice:

$ cat tst.f90
module x
  implicit none
contains
  double precision function v2s(v)
    integer, dimension(8), intent(in) :: v
    v2s = v(8)*1d-3+v(7)+v(6)*60.d0+v(5)*3600.d0
  end function v2s
end module x
program main
  use x
  implicit none
  integer, parameter :: n=10**7
  real, dimension(n) :: a
  real:: t1, t2
  integer :: i
  integer, dimension(8) :: v1, v2

  call random_number(a)
  open(unit=10,file="test.dat",form="unformatted")
  call cpu_time(t1)
  call date_and_time(values=v1)
  write (10) (a(i),i=1,n)
  call date_and_time(values=v2)
  call cpu_time(t2)
  print *,"CPU time implied DO loop = ", t2-t1
  print *,"Wall time = ", v2s(v2)-v2s(v1)

  call cpu_time(t1)
  call date_and_time(values=v1)
  write (10) a(1:i:1)
  call cpu_time(t2)
  call date_and_time(values=v2)
  print *,"CPU time Array= ", t2-t1
  print *,"Wall time = ", v2s(v2)-v2s(v1)
  close(10,status="delete")
end program main

$ gfortran -O3 tst.f90
$ ./a.out
 CPU time implied DO loop =   0.374823004
 Wall time =   0.50600000000122236
 CPU time Array=    6.18300140E-02
 Wall time =   0.10599999999976717
$




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