program test
  implicit none
  integer, parameter :: n = 100000
  real :: t1, t2
  character(len=100) :: s
  integer :: i

  integer(kind=1) :: x1(n) 
  integer(kind=4) :: x4(n) 
  integer(kind=8) :: x8(n) 
  integer(kind=16) :: x16(n) 

  print *, "Timing for INTEGER(KIND=1)"

  x1(:) = 0
  call cpu_time(t1)
  do i = 1, 10
    call output1(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value 0, time:", t2 - t1

  x1(:) = huge(x1)
  call cpu_time(t1)
  do i = 1, 10
    call output1(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value HUGE(KIND=1), time:", t2 - t1

  print *, "Timing for INTEGER(KIND=4)"

  x4(:) = 0
  call cpu_time(t1)
  do i = 1, 10
    call output4(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value 0, time:", t2 - t1

  x4(:) = 1049
  call cpu_time(t1)
  do i = 1, 10
    call output4(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value 1049, time:", t2 - t1

  x4(:) = huge(x4)
  call cpu_time(t1)
  do i = 1, 10
    call output4(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value HUGE(KIND=4), time:", t2 - t1

  print *, "Timing for INTEGER(KIND=8)"

  x8(:) = 0
  call cpu_time(t1)
  do i = 1, 10
    call output8(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value 0, time:", t2 - t1

  x8(:) = huge(x4)
  call cpu_time(t1)
  do i = 1, 10
    call output8(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value HUGE(KIND=4), time:", t2 - t1

  x8(:) = huge(x8)
  call cpu_time(t1)
  do i = 1, 10
    call output8(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value HUGE(KIND=8), time:", t2 - t1

  print *, "Timing for INTEGER(KIND=16)"

  x16(:) = 0
  call cpu_time(t1)
  do i = 1, 10
    call output16(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value 0, time:", t2 - t1

  x16(:) = huge(x4)
  call cpu_time(t1)
  do i = 1, 10
    call output16(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value HUGE(KIND=4), time:", t2 - t1

  x16(:) = huge(x8)
  call cpu_time(t1)
  do i = 1, 10
    call output16(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value HUGE(KIND=8), time:", t2 - t1

  x16(:) = huge(x16)
  call cpu_time(t1)
  do i = 1, 10
    call output16(s)
  end do
  call cpu_time(t2)
  write(*,*) "Value HUGE(KIND=16), time:", t2 - t1

contains
  subroutine output1(s)
    implicit none
    character(len=100) :: s
    integer :: i

    do i = 1, n
      write(s,*) x1(i)
    end do
  end subroutine

  subroutine output4(s)
    implicit none
    character(len=100) :: s
    integer :: i

    do i = 1, n
      write(s,*) x4(i)
    end do
  end subroutine

  subroutine output8(s)
    implicit none
    character(len=100) :: s
    integer :: i

    do i = 1, n
      write(s,*) x8(i)
    end do
  end subroutine

  subroutine output16(s)
    implicit none
    character(len=100) :: s
    integer :: i

    do i = 1, n
      write(s,*) x16(i)
    end do
  end subroutine
end
