Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran

Idiom #125 Measure function call duration

measure the duration t, in nanoseconds, of a call to the function foo. Print this duration.

integer, parameter :: i8 = selected_int_kind(15)
integer (kind=i8) :: count, count_rate, count_2
x = 1.2
call system_clock (count, count_rate)
call foo
call system_clock (count_2)
if (count_rate == 10**9) then
  print *,"The call to foo used ", (count_2-count), "Nanoseconds"
else
  print *,"The call to foo used ", (count_2-count)/real(count_rate)*1e9, "Nanoseconds"
end if
(time (foo))

time prints time elapsed, but in ms

New implementation...
< >
JPSII