Next: , Previous: now.h, Up: Interface


4.13 cycles.h: access to CPU cycle counting registers.

Some modern CPU's provide user accessible registers or special intstructions which can access a counter driven directly by the CPU clock. The ‘cycles.h’ library provides access to these instructions together with some calibration and utility routines.

Currently we only provide support for Pentium/Cyrix machines using the ‘RDTSC’ instruction. If you want to use these routines you need to run the ‘configure’ script with the ‘--enable-rdtsc’ option. Other machine architectures will be supported as time goes on.

— typedef: CYCLES long long

The CPU cycle measurement type, typically a 64 bit unsigned integer.

— Macro: CYCLES cycles ()

Returns the current value for the cycle counter.

— Function: CYCLES cycles_per_second (double t, int n)

Returns an estimate of the number of cycles per second using the ‘now.h’ library. The measurement is taken n times using a measurement period of t seconds for each measurement. The minimum and maximum values for the measurement are set by each call to ‘cycles_per_second’ and are available from the next two functions.

— Function: CYCLES cycles_per_second_min ()
— Function: CYCLES cycles_per_second_max ()

Return the minimum or maximum of the measurements carried out by the previous call to ‘cycles_per_second’.

— Function: double cycles_diff (CYCLES start, CYCLES stop)

Returns the time difference between start and stop cycles in seconds as a double. As usual there are a few requirements:


Footnotes

[1] Famous last words I know but: (2^64)/(1e9*60*60*24*365) = 584 yrs.