Array copy using subscript triplet

To do array copy from A(:,:,2) to A(:,:,1),
which of these results in better performance?

A(:,:,1) = A(:,:,2)

OR

DO 10 J=1,JMAX
  DO 10 I=1,IMAX
    A(I,J,1)=A(I,J,2)
10 CONTINUE

Hi Mr.Smith,

Assuming you compile at -O2 or above, the first will be faster since the implied do loop will be replaced by a memcpy.

Hope this helps,
Mat

$ cat cpy.f90 

program test

   real :: A(100,100,2)
   A(:,:,1) = A (:,:,2)
   print *, A(1,1,1)

end program test

$ pgf90 -O2 -Minfo cpy.f90 
test:
      5, Memory copy idiom, loop replaced by call to __c_mcopy4