tsc_clock#
Fully qualified name: carb::clock::tsc_clock
Defined in carb/clock/TscClock.h
-
class tsc_clock#
Static class for a CPU time-stamp clock.
The functions and types within this class are used for sampling the CPU’s time-stamp counter—typically a clock- cycle resolution clock directly within the CPU hardware.
Public Types
Public Static Functions
-
static inline bool isInvariant() noexcept#
Checks whether the system supports an invariant (time-based) TSC clock.
Warning
If this returns false, results from sample() may appear to run backwards.
- Returns:
true if the CPU supports an invariant TSC clock; false otherwise.
-
static inline Sample sample() noexcept#
Read a sample from the CPU time-stamp clock.
Note that this operation is intended to be as fast as possible to maintain accuracy.
Warning
If isInvariant() is false, results from this function may appear to run backwards.
- Returns:
a time-stamp Sample at the time the function is called.
-
static inline Freq frequency() noexcept(!1)#
Computes the frequency of the CPU time-stamp clock.
The first call to this function can take longer as the CPU time-stamp clock is calibrated.
Note
This implementation assumes that the frequency never changes. Please verify with your CPU architecture that this assumption is correct.
Warning
If isInvariant() returns false, this frequency may not be stable and may throw std::runtime_error.
-
template<class Duration>
static inline Duration duration(
) noexcept# Computes the difference of two samples as a std::chrono::duration.
- Template Parameters:
Duration – a
std::chrono::durationtemplate to convert to.- Parameters:
older – The older (starting) sample
newer – The newer (ending) sample
- Returns:
The difference in timestamps as the requested
Durationrepresentation
-
static inline bool isInvariant() noexcept#