Gromacs
2016.4

#include "config.h"
Highresolution timestamp or CPU clock cycle counters.
After reading the current value with gmx_cycles_read() you can add or subtract these numbers as normal integers of type gmx_cycles_t.
Typedefs  
typedef long  gmx_cycles_t 
Integerlike datatype for cycle counter values. More...  
Functions  
static __inline__ gmx_cycles_t  gmx_cycles_read (void) 
Read CPU cycle counter. More...  
static __inline__ int  gmx_cycles_have_counter (void) 
Check if highresolution cycle counters are available. More...  
double  gmx_cycles_calibrate (double sampletime) 
Calculate number of seconds per cycle tick on host. More...  
typedef long gmx_cycles_t 
Integerlike datatype for cycle counter values.
Depending on your system this will usually be something like long long, or a special cycle datatype from the system header files. It is NOT necessarily real processor cycles  many systems count in nanoseconds or a special external time register at fixed frequency (not the CPU freq.)
You can subtract or add gmx_cycle_t types just as normal integers, and if you run the calibration routine you can also multiply it with a factor to translate the cycle data to seconds.
double gmx_cycles_calibrate  (  double  sampletime  ) 
Calculate number of seconds per cycle tick on host.
This routine runs a timer loop to calibrate the number of seconds per the units returned fro gmx_cycles_read().
sampletime  Minimum real sample time. It takes some trialanderror to find the correct delay loop size, so the total runtime of this routine is about twice this time. 

static 
Check if highresolution cycle counters are available.
Not all architectures provide any way to read timestep counters in the CPU, and on some it is broken. Although we refer to it as cycle counters, it is not necessarily given in units of cycles.
If you notice that system is missing, implement support for it, find out how to detect the system during preprocessing, and send us a patch.

static 
Read CPU cycle counter.
This routine returns an abstract datatype containing a cycle counter timestamp.
Please note that on most systems it takes several cycles to read and return the cycle counters. If you are measuring small intervals, you can compensate for this time by calling the routine twice and calculating what the difference is. Subtract this from your other measurements to get an accurate result.
Use gmx_cycles_difference() to get a real number corresponding to the difference between two gmx_cycles_t values returned from this routine.