help_text=[ CHARACTER(LEN=128) :: &
howlong(1) - display wallclock time taken to execute a system command
Synopis
Description
Sample Subject Program
Footnotes
Options
Example
See Also
howlong SYSTEM_COMMAND
orhowlong --help|--version
Perhaps the simplest performance metric is to just measure the wallclock time taken by a program. This could literally be measured using a conventional clock or stopwatch. This is difficult to automate! So typically a command like the GNU/Linux or Unix command time(1) is used.
Commands such as time(1) often provide more than wallclock times too. But lets construct a wallclock timing tool of our own using standard Fortran (not even the ISO_C_Binding interface will be called upon) that will measure the run time of a command.
Once passed a command to time on the command line, it will then run the command and report the wallclock time use by the program, and echo the command.
Next we provide a simple program that calls the routine(s) of interest enough times to get useful timing information and time it.
So lets say we compiled up the test program using two different sets of compiler options:
f90 little_test.f90 -O0 -o little_test0 f90 little_test.f90 -O3 -o little_test3Now to run the programs via our timing utility only takes a few commands:
howlong ./little_test0 Wallclock: 0-00:00:25.461 :command: ./little_test0 howlong ./little_test3 Wallclock: 0-00:00:10.274 :command: ./little_test3
An uninstrumented test program for timing :
program little_test use,intrinsic :: iso_fortran_env, only : int8 implicit none character(len=*),parameter :: original = "abcdxyz ZXYDCBA _!@" integer,parameter :: how_many_times = 100000000 character(len=:),volatile,allocatable :: t integer :: i do i=1,how_many_times t=upper(original) t=lower(original) enddo contains function upper(str) result(translated) integer(kind=int8), parameter :: & & ascii_diff = abs(iachar(A,kind=int8) - iachar(a,kind=int8)) character(*), intent(in) :: str integer :: i character(len=len(str)) :: translatedtranslated=str do i = 1, len(str) select case(str(i:i)) case("a":"z") translated(i:i) = achar(iachar(str(i:i))-ascii_diff) end select enddo end function upper
function lower(str) result(translated) integer(kind=int8), parameter :: & & ascii_diff = abs(iachar(A,kind=int8) - iachar(a,kind=int8)) character(*), intent(in) :: str integer :: i character(len=len(str)) :: translated
translated=str do i = 1, len(str) select case(str(i:i)) case("A":"Z") translated(i:i) = achar(iachar(str(i:i))+ascii_diff) end select enddo end function lower
end program little_test
Note that in many HPC environments programs are often run via a job scheduler like Slurm, LSF, PBS, Torque, ... . In these environments there are usually account records of each job that provide resource usage statistics.
--help display this help and exit --version output version information and exit
howlong ./myprogram
gprof(1), gcov(1)
Nemo Release 3.1 | howlong (1) | February 23, 2025 |