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.
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.
Return the minimum or maximum of the measurements carried out by the previous call to ‘cycles_per_second’.
Returns the time difference between start and stop cycles in seconds as a double. As usual there are a few requirements:
- ‘cycles_per_second’ must be called before hand to calibrate the cycle time with the real time clock.
- start must be less than or equal to stop. Note we do not handle wraparound currently since the counters start at 0 and are 64 bits long and so will not overflow in a reasonable period. 1
- The difference between the start and stop times should be able to be represented in a ‘double’, lest overflow and misery follow.
- CPU clocks tend to vary a bit with temperature etc, trust this and die.