Unix standard C libraries provide a number of standard function calls for getting timing data from your program. A simple form of instrumentation may be achieved by logging milestones and time measurements during the execution of a program. While logging does impact runtime performance, it can be targeted to specific locations in the code rather than applied globally.

The following table describes the library calls available for various Unix systems.

Routine Include File Type Resolution (usec) OS/Compiler
times sys/times.h user, sys 1000 Linux, AIX, IRIX, UNICOS
getrusage sys/resource.h wall, user, sys 1000 Linux, AIX, IRIX
gettimeofday sys/time.h wall 1 Linux, AIX, IRIX, UNICOS
__rdtsc x86intrin.h wall 0.1 Linux
read_real_time sys/time.h wall 0.001 AIX
system_clock (n/a) wall (system dependent) Fortran 90 intrinsic
MPI_Wtime mpi.h wall MPI_Wtick MPI Library (C, Fortran)
omp_get_wtime omp.h wall omp_get_wtick OpenMP Library (C, Fortran)

Generally, these functions return some form of a timestamp, so you'll need to calculate differential times in order to measure execution time. The exception is getrusage, which records the time utilization by the calling process. Differential measurements usually take the following form:

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement