timer

ソースコード

 1#include <iostream>
 2#include <chrono>
 3
 4using namespace std;
 5
 6// Timer
 7namespace titan23 {
 8
 9    /**
10     * @brief 時間計測クラス
11     */
12    class Timer {
13    private:
14        chrono::time_point<chrono::high_resolution_clock> start_timepoint;
15
16    public:
17        Timer() : start_timepoint(chrono::high_resolution_clock::now()) {}
18
19        //! リセットする
20        void reset() {
21            start_timepoint = chrono::high_resolution_clock::now();
22        }
23
24        //! 経過時間[ms](double)を返す
25        double elapsed() const {
26            auto end_timepoint = chrono::high_resolution_clock::now();
27            auto start = chrono::time_point_cast<chrono::microseconds>(start_timepoint).time_since_epoch().count();
28            auto end = chrono::time_point_cast<chrono::microseconds>(end_timepoint).time_since_epoch().count();
29            return (end - start) * 0.001;
30        }
31    };
32}  // namespace titan23

仕様

Warning

doxygenfile: Cannot find file “titan_cpplib/ahc/timer.cpp