• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    class
    <chrono>

    std::chrono::high_resolution_clock

    namespace std {
    namespace chrono {
      class high_resolution_clock;
    }}
    

    概要

    high_resolution_clockは、そのプラットフォームでの最も短い間隔のクロックである。

    このクラスは、system_clocksteady_clockの別名として定義される場合がある。

    メンバ関数

    静的メンバ関数

    名前 説明 対応バージョン
    now 現在日時を取得する C++11

    メンバ型

    名前 説明 対応バージョン
    rep 時間間隔の内部表現となる算術型 C++11
    period 時間の周期を表すratio C++11
    duration 時間間隔の型 C++11
    time_point 時間の一点を指す型 C++11

    メンバ定数

    名前 説明 対応バージョン
    static const bool is_steady 逆行しないクロックかどうかを表すbool値。値は未規定 C++11まで
    static constexpr bool is_steady 逆行しないクロックかどうかを表すbool値。値は未規定 C++14から

    #include <chrono>
    #include <iostream>
    #include <thread>
    
    using namespace std::chrono;
    
    int main()
    {
      // 1. 現在日時を取得
      high_resolution_clock::time_point begin = high_resolution_clock::now();
    
      // 2. 時間のかかる処理...
      std::this_thread::sleep_for(seconds(3));
    
      // 3. 現在日時を再度取得
      high_resolution_clock::time_point end = high_resolution_clock::now();
    
      // 経過時間を取得
      seconds elapsed_time = duration_cast<seconds>(end - begin);
      std::cout << elapsed_time.count() << "秒" << std::endl;
    }
    

    出力例

    3秒
    

    バージョン

    言語

    • C++11

    処理系

    • GCC: 4.6.1
    • Visual C++: 2012 , 2013 , 2015
      • 2015でsteady_clockの別名に実装が変更された。これはWindows APIのQueryPerformanceCounter関数を使用した実装である。

    参照