Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::chrono::high_resolution_clock

      From cppreference.com
      <cpp‎ |chrono
       
       
      Date and time library
      Time point
      (C++11)
      (C++20)
      Duration
      (C++11)
      Clocks
      (C++20)
      (C++20)
      (C++20)
      high_resolution_clock
      (C++11)
      (C++20)
      (C++20)
      (C++20)
      Time of day
      (C++20)(C++20)
      (C++20)(C++20)
      (C++20)
       
      std::chrono::high_resolution_clock
       
      Defined in header<chrono>
      class high_resolution_clock;
      (since C++11)

      Classstd::chrono::high_resolution_clock represents the clock with the smallest tick period provided by the implementation. It may be an alias ofstd::chrono::system_clock orstd::chrono::steady_clock, or a third, independent clock.

      std::chrono::high_resolution_clock meets the requirements ofTrivialClock.

      Contents

      [edit]Member types

      Type Definition
      rep arithmetic type representing the number of ticks in the clock's duration
      period astd::ratio type representing the tick period of the clock, in seconds
      durationstd::chrono::duration<rep, period>
      time_pointstd::chrono::time_point<std::chrono::high_resolution_clock>

      [edit]Member constants

      constexpr bool is_steady
      [static]
      true if the time between ticks is always constant, i.e. calls tonow() return values that increase monotonically even in case of some external clock adjustment, otherwisefalse
      (public static member constant)

      [edit]Member functions

      [static]
      returns astd::chrono::time_point representing the current value of the clock
      (public static member function)

      [edit]Notes

      There has been some controversy around the use ofhigh_resolution_clock. Howard Hinnant, who claims to have introducedhigh_resolution_clock to the language, stated in 2016 on theISO C++ Standard - Discussion mailing list that he was in favor of deprecating it. His rationale was that, because the standard allows for it to be an alias forstd::chrono::steady_clock orstd::chrono::system_clock, its use adds uncertainty to a program without benefit. However, other participants in the thread spoke out its favor, for instance on the basis that, because neitherstd::chrono::steady_clock norstd::chrono::system_clock come with any particular resolution guarantees,high_resolution_clock serves a useful role by giving the vendor an opportunity to supply the platform's highest-resolution clock, when neither itsstd::chrono::steady_clock nor itsstd::chrono::system_clock would be that.

      It is often just an alias forstd::chrono::steady_clock orstd::chrono::system_clock, but which one it is depends on the library or configuration. When it is asystem_clock, it is not monotonic (e.g., the time can go backwards). For example, as of 2023, libstdc++ has it aliased tosystem_clock "until higher-than-nanosecond definitions become feasible"[1], MSVC has it assteady_clock[2], and libc++ usessteady_clock when the C++ standard library implementation supports a monotonic clock andsystem_clock otherwise[3].

      [edit]See also

      wall clock time from the system-wide realtime clock
      (class)
      monotonic clock that will never be adjusted
      (class)

      [edit]External links

      1. libstdc++<chrono.h>
      2. MSVChigh_resolution_clock
      3. libc++<high_resolution_clock.h>
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/high_resolution_clock&oldid=178562"

      [8]ページ先頭

      ©2009-2025 Movatter.jp