title: Fortran performance when passing array slices as arguments
body: <p>I like fortran's array-slicing notation (<code>array(1:n)</code>), but I wonder whether I take a performance hit if I use them when it's not necessary.</p>
  
  <p>Consider, for example, this simple quicksort code (It works, but obviously it's not taking care to pick a good pivot): </p>
  
  <pre><code>recursive subroutine quicksort(array, size)
  
      real, dimension(:), intent(inout) :: array
      integer, intent(in) :: size
      integer :: p
  
      if (size &gt; 1) then
          p = partition(array, size, 1)
          call quicksort(array(1:p-1), p-1)
          call quicksort(array(p+1:size), size-p)
      end if
  
  end subroutine quicksort
  
  function partition(array, size, pivotdex) result(p)
  
      real, dimension(:), intent(inout) :: array
      integer, intent(in) :: size, pivotdex
      real :: pivot
      integer :: i, p
  
      pivot = array(pivotdex)
      call swap(array(pivotdex), array(size))
  
      p=1
      do i=1,size-1
          if (array(i) &lt; pivot) then
              call swap(array(i), array(p))
              p=p+1
          end if
      end do
  
      call swap(array(p), array(size))
  
  end function partition
  
  subroutine swap(a, b)
  
      real, intent(inout) :: a, b
      real :: temp
      temp = a
      a = b
      b = temp
  
  end subroutine swap    
  </code></pre>
  
  <p>I could just as easily pass the whole array along with the indices of where the recursive parts should be working, but I like the code this way. When I call <code>quicksort(array(1:p-1), p-1)</code>, however, does it make a temporary array to operate on, or does it just make a shallow reference structure or something like that? Is this a sufficiently efficient solution?</p>
  
  <p><a href="https://stackoverflow.com/questions/28859524/fortran-runtime-warning-temporary-array">This question</a> is related, but it seems like it makes temporary arrays because of the strided slice and explicit-sized dummy variables, so I'm safe from that, right?</p>