I upvoted R. Martinho Fernandes's answer because I believe it offers the clearest, most straightforward answer to the question. However I wanted to add a little code that showed a little more <chrono>
functionality and that addressed this part of the OP's question:
can I somehow at least get a count in nanoseconds of the minimum
representable time duration between ticks?
And it is impractical to put this much information into a comment. But I otherwise regard this answer as a supportive comment to R. Martinho Fernandes's answer.
First the code, and then the explanation:
#include <iostream>
#include <chrono>
template <class Clock>
void
display_precision()
{
typedef std::chrono::duration<double, std::nano> NS;
NS ns = typename Clock::duration(1);
std::cout << ns.count() << " ns\n";
}
int main()
{
display_precision<std::chrono::high_resolution_clock>();
display_precision<std::chrono::system_clock>();
}
First I created a nanosecond
that is using a double
as the representation (NS
). I used double
just in case I needed to show fractions of a nanosecond (e.g. 0.5 ns
).
Next, every clock has a nested type named duration
. This is a chrono::duration
that will have the same std::ratio
, and thus the same num
and den
as pointed out in R. Martinho Fernandes's answer. One of those duration
s, converted to NS
will give us how many nanoseconds in one clock tick of Clock
. And that value can be extracted from the duration
with the count()
member function.
For me this program prints out:
1 ns
1000 ns