cp-library

C++ Library for Competitive Programming

View the Project on GitHub emthrm/cp-library

:warning: タイマー (timer)
(include/emthrm/util/timer.hpp)

仕様

struct Timer;

メンバ変数

名前 効果・戻り値
Timer(); コンストラクタ
void reset(); リセットする。
template <typename PeriodType = std::chrono::milliseconds>
long long elapsed() const;
経過時間

参考文献

Code

#ifndef EMTHRM_UTIL_TIMER_HPP_
#define EMTHRM_UTIL_TIMER_HPP_

#include <chrono>

namespace emthrm {

struct Timer {
  Timer() { reset(); }

  void reset() { bgn = std::chrono::high_resolution_clock::now(); }

  template <typename PeriodType = std::chrono::milliseconds>
  long long elapsed() const {
    const std::chrono::high_resolution_clock::time_point end =
        std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<PeriodType>(end - bgn).count();
  }

 private:
  std::chrono::high_resolution_clock::time_point bgn;
};

}  // namespace emthrm

#endif  // EMTHRM_UTIL_TIMER_HPP_
#line 1 "include/emthrm/util/timer.hpp"



#include <chrono>

namespace emthrm {

struct Timer {
  Timer() { reset(); }

  void reset() { bgn = std::chrono::high_resolution_clock::now(); }

  template <typename PeriodType = std::chrono::milliseconds>
  long long elapsed() const {
    const std::chrono::high_resolution_clock::time_point end =
        std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<PeriodType>(end - bgn).count();
  }

 private:
  std::chrono::high_resolution_clock::time_point bgn;
};

}  // namespace emthrm
Back to top page