macro LIBBENCHMARK_PAL_GET_HIGHRES_TIME

From liblfds.org
Revision as of 07:40, 27 May 2016 by Admin (talk | contribs) (Created page with "{{DISPLAYTITLE:macro LIBBENCHMARK_PAL_GET_HIGHRES_TIME}} ==Source File== └───test_and_benchmark └───libbenchmark └───inc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source File

└───test_and_benchmark
    └───libbenchmark
        └───inc
            └───libbenchmark
                    libbenchmark_porting_abstraction_layer_operating_system.h

Define

#define LIBBENCHMARK_PAL_GET_HIGHRES_TIME( pointer_to_time )

Example

#define LIBBENCHMARK_PAL_GET_HIGHRES_TIME( pointer_to_time )                          \
{                                                                                     \
  struct timespec tp;                                                                 \
  clock_gettime( CLOCK_MONOTONIC_RAW, &tp );                                          \
  *(pointer_to_time) = tp.tv_sec * NUMBER_OF_NANOSECONDS_IN_ONE_SECOND + tp.tv_nsec;  \
}

Optionality

This define is mandatory and the library cannot compile if it is not set.

Notes

The benchmarks, to be fair, must be accurate in their duration. This requires much better than the one second accurately of time_t or the uncertainties of clock_t and so we turn to high resolution timers, which are typically backed by the clock running the processor's operating frequency.

Two macros are provided to access the high resolution clock. The first, this macro, gets the current time. The value returned by this macro is correct but arbitrary. To convert it to seconds, we must also know how many units of the returned time equal one second, and that is the purpose of this macro, LIBBENCHMARK_PAL_TIME_UNITS_PER_SECOND.

Generally, operating systems present high resolution timers using the same two functions (get the current time / how many units per second), but Linux is different and normalizes everything to nanoseconds. As such, there is no function to determine how many time units pass in one second - it's simply the number of nanoseconds in one second (indeed, Linux is actually reporting time in nanoseconds, so conversion isn't required).

See Also