1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
program test
implicit none
integer :: i
integer, parameter :: n = 1000000
integer :: t2, t1, freq, maxt, nb_periodes
real, dimension(n) :: a, sqrta
real :: x, cpu1, cpu2, tps_systeme
call system_clock( count_rate=freq, count_max=maxt )
! a entre -1 et 1
do i = 1, n
call random_number(x)
a(i) = 2.d0 * x - 1.d0
end do
!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
! bloc where
!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
call system_clock( t1 )
call cpu_time( cpu1 )
where ( a(:) > 0.d0 )
sqrta(:) = sqrt(a(:))
else where
sqrta(:) = 0.d0
end where
call cpu_time( cpu2 )
call system_clock( t2 )
nb_periodes = t2 - t1
do while ( nb_periodes < 0 )
nb_periodes = nb_periodes + maxt
end do
tps_systeme = real(nb_periodes) / real(freq)
write(*,"('bloc where')")
write(*,"('temps cpu :',F10.4)") cpu2 - cpu1
write(*,"('temps systeme :',F10.4)") tps_systeme
!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
! bloc do if else end do
!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
call system_clock( t1 )
call cpu_time( cpu1 )
do i = 1, n
if( a(i) > 0.d0 ) then
sqrta(i) = sqrt(a(i))
else
sqrta(i) = 0.d0
end if
end do
call cpu_time( cpu2 )
call system_clock( t2 )
write(*,*)
write(*,"('bloc do if then else end if end do')")
nb_periodes = t2 - t1
do while ( nb_periodes < 0 )
nb_periodes = nb_periodes + maxt
end do
tps_systeme = real(nb_periodes) / real(freq)
write(*,"('temps cpu :',F10.4)") cpu2 - cpu1
write(*,"('temps systeme :',F10.4)") tps_systeme
end program test |
Partager