Microbenchmarks icon indicating copy to clipboard operation
Microbenchmarks copied to clipboard

Update 'print_to_file' Fortran benchmark

Open gha3mi opened this issue 3 years ago • 2 comments

The use of implied DO-loops leads to a better performance, see link.

gha3mi avatar Jun 23 '22 08:06 gha3mi

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.

zoziha avatar Jun 23 '22 08:06 zoziha

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

gha3mi avatar Jun 23 '22 09:06 gha3mi

But I'm not sure if using an implicit do loop is "cheating"? Other languages ​​use the usual for loop.

zoziha avatar Jun 23 '22 10:06 zoziha