TicToc routine - Fortran
Copy the file src/tictoc_mod.f90 or add the package as a dependence using the Fortran Package Manager (Fpm):
[dependencies]
tictoc-fortran.git = "https://github.com/wcota/tictoc-fortran"Import the module using use tictoc_mod. This package provides the tictoc_t object. Create one using
type(tictoc_t) :: ctimerReset the timer:
call ctimer%reset()Use the tic to start the clock, and toc to pause it:
call ctimer%tic()
! do something
call ctimer%toc()
! do anything else
call ctimer%tic()
! do something
call ctimer%toc()To see how much time was spent doing something, use the real variable t_tot:
write(*,*) ctimer%t_totA possible usage would be to stop the simulation after x samples if the program is taking too long:
call ctimer%reset()
call ctimer%tic()
sampling: do sample=1,1000
if (ctimer%now() > 5.0_dp * 60.0_dp) exit sampling
! dynamics
enddo samplingAn example is available at example/example.f90. To run it with Fpm, use fpm run --example. Expected output:
Project is up to date
CPU TIME =
0.35635800000000001
Now measuring inside the loop...
CPU TIME =
0.57127699999999348Tested with gfortran, ifort and ifx compilers.