Open gha3mi opened 2 years ago
Yes, an implicit do loop (for perf.f90) is more efficient:
subroutine printfd(n)
integer, intent(in) :: n
integer :: i
character(*), parameter :: newline = new_line("")
open(unit=1, file="/dev/null")
write(unit=1, fmt=*) (i, i+1, newline, i=1, n)
close(unit=1)
end subroutine
newline
is a carriage return.
Maybe we can create a PR for this.
Thanks @zoziha. I have checked your version with gfortran and ifort. Could you please create a PR?
Using GNU Fortran (GCC) 12.1.0: gfortran perf.f90 |
Previous Version | New Version |
---|---|---|
23.536152 | 9.529248 |
Using ifort (IFORT) 2021.5.0 20211109: ifort perf.f90 |
Previous Version | New Version |
---|---|---|
31.675000 | 14.640000 |
But I'm not sure if using an implicit do
loop is "cheating"? Other languages use the usual for
loop.
The use of implied DO-loops leads to a better performance, see link.