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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With