Defined in carb/time/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

using Sample = ::carb::Strong<uint64_t, struct SampleSig>

Type definition of a sample from the CPU time-stamp counter.

The time units of this are unspecified. Use Freq to determine the frequency of the time-stamp counter.

using Freq = ::carb::Strong<uint64_t, struct FreqSig>

The frequency of the timestamp counter, that is, the number of Samples per second.

Public Static Functions

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.


a time-stamp Sample at the time the function is called.

static inline Freq frequency() noexcept

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.


This implementation assumes that the frequency never changes. Please verify with your CPU architecture that this assumption is correct.


the computed Freq of the CPU time-stamp clock.

template<class Duration>
static inline Duration duration(Sample older, Sample newer) noexcept

Computes the difference of two samples as a std::chrono::duration.

Template Parameters

Duration – a std::chrono::duration template to convert to.

  • older – The older (starting) sample

  • newer – The newer (ending) sample


The difference in timestamps as the requested Duration representation