Skip to main content

Timing tools

âš  INFORMATION
This page was translated by an AI (LLM) with a cursory human check and is awaiting full review.

Unix command to measure time​

The Unix command time displays the execution time of an executable after it has finished running. Here is an example:

time ./mon_executable    real    0m1.43s    user    0m0.08s    sys     0m0.16s
  • The wall-clock time or Elapsed time corresponds to line real;
  • The system time corresponds to line sys, which gives an indication of the load related to input/output (read/write operations on the hard disk).

Wall-clock time in Fortran: SYSTEM_CLOCK​

Fortran 90 intrinsic subroutine that provides an Elapsed time by returning the number of clock periods consumed. Here is an example of its use:

INTEGER(kind=8) :: &
nb_periodes_initial, & ! valeur initiale du compteur de périodes d'horloge
nb_periodes_final, & ! valeur finale du compteur de périodes d'horloge
nb_periodes_max, & ! valeur maximale du compteur d'horloge
nb_periodes_sec, & ! nombre de périodes d'horloge par seconde
nb_periodes ! nombre de périodes d'horloge du code
REAL(kind=8) :: temps_elapsed ! temps réel en secondes

! Initialisations
CALL SYSTEM_CLOCK(COUNT_RATE=nb_periodes_sec, COUNT_MAX=nb_periodes_max)
...
CALL SYSTEM_CLOCK(COUNT=nb_periodes_initial)
...
! <<<<<<<<<<<<< partie du code à évaluer >>>>>>>>>>>>>
...
CALL SYSTEM_CLOCK(COUNT=nb_periodes_final)
nb_periodes = nb_periodes_final - nb_periodes_initial
IF (nb_periodes_final < nb_periodes_initial) &
nb_periodes = nb_periodes + nb_periodes_max
temps_elapsed = REAL(nb_periodes) / nb_periodes_sec
...

CPU time in Fortran: CPU_TIME​

Fortran 90 intrinsic subroutine that measures the CPU time of a portion of code enclosed between two calls to CPU_TIME. Example of implementation:

implicit none
integer :: j, n
real,dimension(10000) :: x
real :: t1,t2
...
call CPU_TIME( t1 )
!do j=1,10000
! x(j)=log(23.)*j
!end do
x(:) = log(23.)*[ (j,j=1,10000) ]
call CPU_TIME( t2 )
...
read *, n ; print *, x(n)
print *,t2 - t1
...
note
  • The variables t1 and t2 are of real type; the result of CPU_TIME is measured in seconds.
  • If the returned argument is negative, the functionality is not available.