Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

std::chrono::steady_clock: a monotonic interval clock

std::chrono::steady_clock never moves backward as physical time advances and progresses at a steady rate.

Version: C++23

Syntax

class steady_clock {
public:
    using rep = /* unspecified arithmetic type */;
    using period = /* unspecified std::ratio specialization */;
    using duration = std::chrono::duration<rep, period>;
    using time_point = std::chrono::time_point<steady_clock, duration>;
    static constexpr bool is_steady = true;
    static time_point now() noexcept;
};

std::chrono::steady_clock from <chrono> is monotonic: successive time_point values do not decrease, and is_steady is true. now() returns a time point without throwing. Subtracting two readings gives a duration, making this clock suitable for execution timing, deadlines, and timeouts.

Its epoch, rep representation type, and period are unspecified by the standard. A value is not a calendar date and should not be persisted as a portable timestamp across systems or runs; differences between points from the same clock are what matter.

The resolution stated by period does not guarantee equal measurement accuracy. The representation has finite range, so very long calculations must consider overflow. Use system_clock, not steady_clock, for wall-clock and calendar time.

Examples

#include <chrono>
#include <iostream>

int main() {
    using Clock = std::chrono::steady_clock;
    const Clock::time_point start{};
    const auto finish = start + std::chrono::seconds{5};
    std::cout << Clock::is_steady << ' '
              << std::chrono::duration_cast<std::chrono::seconds>(finish - start).count() << '\n';
}

Result

1 5

std::chrono::steady_clock → 1 5

Sources