
Table des matières
Jean Zay: Time measurement tools
Unix time measurement command
The Unix time
command prints the running time of an executable file, after its own outputs.
Here is an example (without any outputs from the executable):
$ time ./my_exe real 0m1.43s user 0m0.08s sys 0m0.16s
The elapsed time corresponds here to the real
line.
The system time corresponds to the sys
line; it gives an indication of the load linked to inputs/outputs (disk operations).
Clock time in Fortran: ''SYSTEM_CLOCK''
SYSTEM_CLOCK is an intrinsic subroutine of Fortran 90 which gives the elapsed time by returning the number of clock periods consumed.
Here is a usage example:
- example.f90
. . . INTEGER(kind=8) :: & nb_periodes_initial, & ! initial value of the counter of clock periods nb_periodes_final, & ! final value of the compter of clock periods nb_periodes_max, & ! maximum value of the clock counter nb_periodes_sec, & ! number of clock periods per second nb_periodes ! number of clock periods of the code REAL(kind=8) :: elapsed_time ! real time in seconds ! Initialisations CALL SYSTEM_CLOCK(COUNT_RATE=nb_periodes_sec, COUNT_MAX=nb_periodes_max) . . . CALL SYSTEM_CLOCK(COUNT=nb_periodes_initial) . . . ! <<<<<<<<<<<<< part of the code to evaluate >>>>>>>>>>>>> . . . 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''
CPU_TIME is a Fortran 90 intrinsic subroutine which measures the
CPU time of a code portion framed by two calls to CPU_TIME
.
Implementation:
- example.f90
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 . . . .
Notes:
- The
t1
andt2
types are real in Fortran; the result ofCPU_TIME
is measured in seconds. - If the returned argument is a negative value, it means that the functionality is not available.