Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measure time taken during Fortran program

Tags:

timing

fortran

I have recently started learning Fortran for the fun of it, and I want to know if there is any simple way to display the time taken to execute my code. It is just simple loop that counts to a million, and I want to see how long it takes to do that.

If it helps, here is the code I'm using:

program count
    implicit none
    integer :: i

    do i=0,1000000
        print*,i
    end do
end program count

I am on Linux using gFortran as my compiler. I am using Geany as a text editor.

like image 739
Progrmr Avatar asked Sep 07 '25 19:09

Progrmr


1 Answers

In Fortran 90 or later, use the SYSTEM_CLOCK intrinsic subroutine:

call system_clock(beginning, rate)
result = do_computation()
call system_clock(end)
print *, "elapsed time: ", real(end - beginning) / real(rate)
like image 184
Stephane Rouberol Avatar answered Sep 10 '25 14:09

Stephane Rouberol