! a_timing.f90 ! ! This is the pattern for making timing measurements of small to ! medium hunks of code. Long running code that takes over 10 seconds ! can usually be measured directly. ! Fill in a subroutine or function or direct code you want to time, ! where indicated by the comments. ! ! 11/7/96 JSS adapted from ACM SIGAda Performance Issues Working Group ! program a_timing use iteration implicit none real :: cpu_time ! actually "wall" time in seconds real :: tolerance ! tolerance on measurement in seconds real :: feature_time ! time for one execution of the feature real :: executions ! number of time feature executed integer, parameter :: check_times = 1000 ! inside loop check integer :: iteration_count ! outer loop count set and varied by iteration logical :: stable ! the timing seems to be OK integer :: outer ! loop variable integer :: inner ! loop variable real :: a ! scratch variable print *, "a_timing example -- your title goes here --" call initialize(iteration_count, check_times) do ! calibrate a control time that accounts for loop and timing overhead call start_control do outer=1,iteration_count global = 0 do inner=1,check_times call increment(global) end do end do call stop_control ! run the actual test in the same construct that was calibrated a = 1.0 ! misc initialization here call start_test do outer=1,iteration_count global = 0 do inner=1,check_times a = a*sin((1.0+a)) call increment(global) end do end do call stop_test call test_stable(iteration_count, stable) if (stable) exit end do if (a == huge(a)) print *, "strange" ! you must use computed variables ! in an "if" test to keep them from ! being optimized away call feature_times(cpu_time, tolerance, feature_time, executions) print *, "feature time=", feature_time, " seconds +/-", tolerance print *, "total test time=", cpu_time, " executions=", executions end program a_timing