Sean Lynch Sean Lynch - 4 days ago 4
C++ Question

std::chrono default duration for time_since_epoch

If I have the following clock and use it to get a count of ticks since the clock's epoch, what does this count actually represent.

std::chrono::high_resolution_clock::now().time_since_epoch().count();


For instance I just ran this and got
1389375799048790227
. What does this number mean? Is it nanoseconds, microseconds, etc?

Answer

The type of the duration is std::chrono::high_resolution_clock::duration. You can inspect a duration's tick period with: std::chrono::high_resolution_clock::duration::period::num and std::chrono::high_resolution_clock::duration::period::den. This is the numerator and denominator of a fraction representing the amount of seconds per tick (e.g. 1/1000000000 for nanoseconds).

The epoch is unspecified, but for you is 1389375799048790227 ticks from when you got that result.

Comments